50 lines
1.3 KiB

5 years ago
import React from 'react';
import logo from './logo.svg';
import './App.css';
import produce from 'immer';
import { useState } from 'react';
function App() {
5 years ago
/*const Notes = props => props.data.map(note => <div>{note.text}</div>);
5 years ago
const initialData = [{ text: 'Hey' }, { text: 'There' }];
const [data, setData] = useState(initialData);
const handleClick = () => {
const text = document.querySelector('#noteinput').value.trim();
if (text) {
const nextState = produce(data, draftState => {
draftState.push({ text });
});
document.querySelector('#noteinput').value = '';
setData(nextState);
}
};
return (
<div className="App">
<input id="noteinput" style={{ width: '80%' }} type="text" placeholder="Enter a new note" />
<button onClick={() => handleClick()}>Add note</button>
<Notes data={data} />
</div>
);
5 years ago
}*/
5 years ago
5 years ago
const [input, setInput] = useState("");
const [list, setList] = useState([]);
5 years ago
5 years ago
const addToList = e => {
setList([ ...list, input ]);
setInput("");
};
5 years ago
return(
<div className="App">
5 years ago
<input type="text" placeholder="First Name" onChange={e => setInput(e.target.value)} />
<button type="button" onClick={addToList}>Submit</button>
<ul>
{list.map(item => <li key={item}>{item}</li>)}
</ul>
</div>
5 years ago
);
}
5 years ago
export default App;