NPM (Node Package Manaher) is used to manage the dependencies for your React project. including the React library itself.
Public folder contains static assets that are served directly to the user's browser, such as images, fonts and the index.html file.
src folder is used to store all the source code of the application which is then responsible for the dynamic changes in your web application.
- index.html file is the
main HTML file (SPA)in React application. - Here the div with
"id=root"will be replaced by thecomponentinside index.js file.
-
ReactDOM is a JavaScript library that renders components to the DOM or browser.
-
The index.js is the JavaScript file that replaces the
rootelement of the index.html file with the newly rendered components.import React from "react"; // import ReactDOM import ReactDOM from "react-dom/client"; import "./index.css"; import App from "./App"; // store the reference of root to a 'root' variable const root = ReactDOM.createRoot( document.getElementById("root") ); // call the render method of the variable. root.render( <React.StrictMode> <App /> </React.StrictMode> );
-
App.js file contains the
root component (App)of React application. -
App component is like a
containerfor other components. -
App.js defines the structure, layout, and routing in the application.
import AppChild from "./Others/AppChild"; function App() { return ( <div> <AppChild/> </div> ) } export default App;
Function
- The function keyword is used to
define a JavaScript functionthat represents your React component. - function is like a
placeholderwhich contains all the code or logic of the component. - The function takes in
propsas its argument (if needed) andreturns JSX.
Return
- return is used to return the
elementfrom the function.
Yes a fucntion without a return statement is possible.
- In that case, your component will not render anything in UI.
- The common use case is for
loggingpurpose.
Export statement is used to make a component available for import using "import" statement in other files.
No the file name and the component name don't have to be the same.
- However, it is recommended to keep them same for easier to organize and understand your code.