Browse Source

completed changes

master
rosh 4 years ago
parent
commit
9d9e4dd694
  1. 46
      src/App.js

46
src/App.js

@ -4,7 +4,13 @@ import './App.css';
import produce from 'immer'; import produce from 'immer';
import { useState } from 'react'; import { useState } from 'react';
function App() {
/*const Notes = props => props.data.map(note => <div>{note.text}</div>); /*const Notes = props => props.data.map(note => <div>{note.text}</div>);
const initialData = [{ text: 'Hey' }, { text: 'There' }]; const initialData = [{ text: 'Hey' }, { text: 'There' }];
const [data, setData] = useState(initialData); const [data, setData] = useState(initialData);
@ -27,23 +33,47 @@ function App() {
</div> </div>
); );
}*/ }*/
function App() {
const [input, setInput] = useState(""); const [input, setInput] = useState("");
const [list, setList] = useState([]); const [list, setList] = useState([]);
const [visible, setVisible] = useState(null);
const addToList = e => { const addToList = e => {
setList([ ...list, input ]); setList([ ...list, input ]);
setInput(""); setInput("");
}; };
const deleteList = id => e => {
setList(list.filter((item, index) => index !== id));
};
function hideMe(){
setVisible(false);
}
let style = { textDecoration: "none" };
if (!visible) style.textDecoration = "line-through";
return( return(
<div className="App"> <div className="App">
<input type="text" placeholder="First Name" onChange={e => setInput(e.target.value)} /> <input type="text" placeholder="First Name" onChange={e => setInput(e.target.value)} />
<button type="button" onClick={addToList}>Submit</button> <button type="button" onClick={addToList}>Submit</button>
<ul> <ul>
{list.map(item => <li key={item}>{item}</li>)} {list.map((item,index) =>
<li key={item} style={style}>
{item}
<button type="button" onClick={deleteList(index)}>Delete</button>
<button type="button" onClick={hideMe}>Completed</button>
</li> )}
</ul> </ul>
</div> </div>
); );
} }
export default App; export default App;

Loading…
Cancel
Save