Create Nested Components in React Functional Components

Create new folder named LearnReactJSWithRealApps and select to this folder in Visual Studio Code

Open Terminal windows in Visual Studio Code and use commands below:

npm install create-react-app@latest
npx create-react-app myapp

Create new js file named Body.js in src folder and create new component as below:

import React from 'react';

function Body() {
  return (
    <h3>Body Component</h3>
  );
}

export default Body;




Create new js file named App.js in src folder and create new component as below:

import React from 'react';

import Body from './Body';

function App() {
  return (
    <div>
      <HeaderComponent/>
      <Body/>
      <FooterComponent/>
    </div>
  );
}

function HeaderComponent() {
  return (
      <h3>Header Component</h3>
  );
}

function FooterComponent() {
  return (
      <h3>Footer Component</h3>
  );
}

export default App;

Open index.js file in src folder and add new component to this file as below:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(<App />, document.getElementById('root'));

serviceWorker.unregister();




In Terminal windows in Visual Studio Code and type: npm start,
program will open url http://localhost:3000 on browser