What is React
-
React is a JavaScript library(using component-based approach) for building user interfaces (UIs)
How React works
React uses a virtual DOM which is a lightweight copy of the real DOM (Document Object Model) to render user interfaces (UI) When data changes, React updates the virtual DOM instead of directly updating the entire DOM. React then uses a diffing algorithm to compare the new and previous virtual DOMs to identify changes. React only updates the parts of the DOM that need to be changed, which reduces the need for full page reloads
Terms
Components
-
React components are JavaScript functions that return markup
export default keyword specify the main component in the file.
function Button() { //This is button component
return (
<button>Submit</button>
);
}
export default function MyApp() { //export default is Starting point
return (
<div>
<h1>Welcome to my app</h1>
<Button /> //button component inside other component
</div>
);
}
Rendering lists
-
will rely on JavaScript features like for loop and the array map() function to render lists of components.
|
Output from Code Welcome to my app - Amit, 1 - tami, 2 |
Event Handler
-
You can respond to events by declaring event handler functions
|
Welcome to my app ------- |Submit| << When click, alert is seen ------- |
Remembering State
-
Often, we want our component to “remember” some information and display it. For example, maybe we want to count the
number of times a button is clicked. To do this, add state to our component
|
![]() |
Sharing data between components
|
![]() |