Create a react or js library, first open terminal and excess you folder using cd .......... and create a react app using create-react-app ...........(name it) like as myapp
App.js
import React, { useState } from "react";
function App() {
const [ticketNumber, setticketNumber] = useState(0);
const [seatNumber, setseatNumber] = useState(0);
function handleticketNumberset(event) {
setticketNumber(event.target.value);
}
function handleseatNumberset(event) {
setseatNumber(event.target.value);
}
return (
<div className = "App">
<input
type="text"
value={ticketNumber}
onChange={handleticketNumberset}
placeholder="Enter Ticket Number"
/>
<h2>Ticket Number : {ticketNumber} </h2>
<input
type="text"
value={seatNumber}
onChange={handleseatNumberset}
placeholder="Enter Seat Number"
/>
<h2>Seat Number : {seatNumber} </h2>
</div>
);
}
export default App;
index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
Excess folder
PS C:\Users\User\Documents\react_ticket> cd ticket
PS C:\Users\User\Documents\react_ticket\ticket>
npm run start to run your code in terminal
Compiled successfully!
You can now view ticket in the browser.
Local: http://localhost:3000
On Your Network: http://192.168.56.1:3000
Note that the development build is not optimized.
To create a production build, use npm run build.
webpack compiled successfully
Result
0 Comments