Skip to content

Instantly share code, notes, and snippets.

@liviaerxin
Last active April 20, 2022 03:47
Show Gist options
  • Save liviaerxin/56407a2b4ed9894cb40cfdec386081f9 to your computer and use it in GitHub Desktop.
Save liviaerxin/56407a2b4ed9894cb40cfdec386081f9 to your computer and use it in GitHub Desktop.
todo
{
"scripts": [
"react",
"react-dom"
],
"styles": [
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.css"
]
}
<div id="app"></div>
function App() {
const [todos, setTodos] = React.useState([
{
"text": "This a sample item",
}
])
const [text, setText] = React.useState(
""
)
const removeTodo = (index) => {
const newTodos = [...todos]
newTodos.splice(index, 1)
setTodos(newTodos)
}
const addTodo = () => {
const newTodos = [...todos, { "text": text }]
setTodos(newTodos)
}
return <div className="container">
<h1>Hi, I'm GistPad</h1>
<p>Feel free to edit the HTML, JavaScript and CSS in the playground. The preview will be updated in real time, so that you can visually explore your ideas.</p>
<button className="fa fa-heart"></button>
<div>
<h1>TODO List</h1>
<div className="f-space">
<input
type="text"
value={text}
onChange={(e) => setText(e.target.value)}
placeholder="Add new todo"
/>
<button onClick={(e) => addTodo()}>add</button>
</div>
{todos.map((todo, index) => (
<div className="f-space">
<span>{todo.text}</span>
<button onClick={(e) => removeTodo(index)}> X </button>
</div>
))}
</div>
</div>
}
ReactDOM.render(<App />, document.getElementById("app"));
body {
background: rgb(193, 193, 182);
}
.container {
margin: 0px 20px;
}
.f-space {
display: flex;
justify-content: space-between;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment