|
1 | | -import { useState } from 'react' |
2 | | -import reactLogo from './assets/react.svg' |
| 1 | +import React from 'react' |
3 | 2 | import './App.css'
|
4 | 3 |
|
5 | 4 | function App() {
|
6 | | - const [count, setCount] = useState(0) |
7 | | - |
| 5 | + |
| 6 | + const [item, setItem] = React.useState(["Item 1,", " Item 2,"]) |
| 7 | + function addItem() { |
| 8 | + setItem( |
| 9 | + prevItem => [...prevItem, ` Item ${prevItem.length + 1}, `] // here i am using spread operater |
| 10 | + ) |
| 11 | + } |
| 12 | + function saveitem() { |
| 13 | + document.getElementById("sv").textContent = item |
| 14 | + } |
8 | 15 | return (
|
9 | 16 | <div className="App">
|
10 | | - <div> |
11 | | - <a href="https://vitejs.dev" target="_blank"> |
12 | | - <img src="/vite.svg" className="logo" alt="Vite logo" /> |
13 | | - </a> |
14 | | - <a href="https://reactjs.org" target="_blank"> |
15 | | - <img src={reactLogo} className="logo react" alt="React logo" /> |
16 | | - </a> |
17 | | - </div> |
18 | | - <h1>Vite + React</h1> |
19 | | - <div className="card"> |
20 | | - <button onClick={() => setCount((count) => count + 1)}> |
21 | | - count is {count} |
22 | | - </button> |
23 | | - <p> |
24 | | - Edit <code>src/App.jsx</code> and save to test HMR |
25 | | - </p> |
26 | | - </div> |
27 | | - <p className="read-the-docs"> |
28 | | - Click on the Vite and React logos to learn more |
29 | | - </p> |
| 17 | + <button onClick={addItem} className="btn" >Add Item</button> |
| 18 | + <b id="in">{item}</b> |
| 19 | + <button onClick={saveitem} className="btn">Save</button> |
| 20 | + <p id='sv'></p> |
30 | 21 | </div>
|
31 | 22 | )
|
32 | 23 | }
|
|
0 commit comments