Pass Simple Values to Props 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




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

import React from 'react';

function App() {

  let age = 20;
  let username = 'abc';
  let status = true;
  let price = 4.5;

  return (
    <div>
      <DislayValues age={age} username={username} status={status} price={price} />
    </div>
  );

}

function DislayValues({ age, username, status, price }) {
  return (
    <div>
      age: {age}
      <br />
      username: {username}
      <br />
      status: {status}
      <br />
      price: {price}
    </div>
  );
}

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