What is JavaScript rendering

SURAJ 91 - Jul 22 - - Dev Community

Redering means 'getting' or 'fetching' data.In JavaScript, rendering refers to the process of displaying the user interface and its elements on the screen.So, Javascript redering refers to the process of generating and displaying content on a web page using JavaScript.This can be crucial for dynamic web applications that need to update content without refreshing the entire page.

Approaches:
There are several approaches to JavaScript redecoding:

Client-Side Redering(CSR)
Sever-Side rendering (SSR)
Static Site Generation (SSG)

Client-Side Redering(CSR):

This is an approach to web development where the rendering of web pages is done on the client side,basically in the user's web browser.That faster initial page load times since only minimal HTML is sent form the server.So, JavaScript fetches data from the server and dynamically updates the DOM to display the content.

syntax:

fetch('api/data')
.then(response => response.json())
.then(data => {
// Update DOM with data
});

`// Import React and useState hook
import React, { useState, useEffect } from 'react';

// Functional component to render content after a delay
const DelayedContent = () => {
// Define state to hold the content
const [content, setContent] = useState(null);

// useEffect hook to fetch data after component mounts
useEffect(() => {
// Simulating fetching data from an API after a delay
const fetchData = async () => {
await new Promise(resolve => setTimeout(resolve, 2000)); // Simulate a delay of 2 seconds
const data = { message: "Hello, world!" };
setContent(data.message); // Set the content after data is fetched
};

fetchData(); // Call the fetchData function
Enter fullscreen mode Exit fullscreen mode

}, []); // Empty dependency array ensures useEffect runs only once after component mounts

// Return JSX to render the content
return (


{/* Render the content once it's available */}
{content &&

{content}

}

);
};

// Export the DelayedContent component
export default DelayedContent;

you can import it and render it within your react app:

import React from 'react';
import ReactDOM from 'react-dom';
import DelayedContent from './DelayedContent';

// Render the DelayedContent component
ReactDOM.render(, document.getElementById('root'));`

Image description

.