Create ReactJS Project
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
Add Image Files
Create new folder named images in public folder. Copy images need to use in project to images folder
Create New Component
Open App.js file in src folder and create new component as below:
import React from 'react';
function App() {
let product = {
id: 'p01',
name: 'name 1',
price: 5,
quantity: 6,
status: true,
photo: 'thumb1.gif'
};
return (
<div>
<h3>Product Info</h3>
<ProductInfo product={product} />
</div>
);
}
function ProductInfo({ product }) {
return (
<div>
id: {product.id}
<br />
name: {product.name}
<br />
price: {product.price}
<br />
quantity: {product.quantity}
<br />
total: {product.price * product.quantity}
<br />
status: {product.status ? 'Show' : 'Hide'}
<br/>
<img src={'./images/' + product.photo} width="120" />
</div>
);
}
export default App;
Add Component to Entry File
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();
Structure of Project
Run Application
In Terminal windows in Visual Studio Code and type: npm start,
program will open url http://localhost:3000 on browser