Skip to content

Instantly share code, notes, and snippets.

@marshallmurphy
Created June 15, 2021 14:20
Show Gist options
  • Save marshallmurphy/4a3414ebbadcf4e94336f0d351f00140 to your computer and use it in GitHub Desktop.
Save marshallmurphy/4a3414ebbadcf4e94336f0d351f00140 to your computer and use it in GitHub Desktop.
const App = () => {
const [todos, setTodos] = useState([]);
const addTodo = (e) => {
e.preventDefault();
if (e.target[0].value.length > 0) {
const todo = e.target[0].value;
const newTodos = [...todos];
newTodos.unshift(todo);
setTodos(newTodos);
e.target[0].value = null;
}
}
const completeTodo = (i) => {
}
const checkboxRow = (todo, i, checked = false) => (
<Flex
width='100%'
justifyContent='space-between'
>
<Label
color='#fff'
>
<Checkbox
checked={checked}
onChange={() => completeTodo(i)}
/>
{todo}
</Label>
</Flex>
);
...
<Box width='350px'>
{todos.map((todo, i) => checkboxRow(todo, i))}
</Box>
</Flex>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment