Skip to content

Instantly share code, notes, and snippets.

View marshallmurphy's full-sized avatar

Tyler Marshal Murphy marshallmurphy

  • Apply Digital
  • Calgary, Alberta
View GitHub Profile
const removeTodo = (i, checked) => {
if (checked) {
const newCompletedTodos = [...completedTodos];
newCompletedTodos.splice(i, 1);
setCompletedTodos(newCompletedTodos);
} else {
const newTodos = [...todos];
newTodos.splice(i, 1);
setTodos(newTodos);
}
const checkboxRow = (todo, i, checked = false) => (
<Flex
width='100%'
justifyContent='space-between'
>
<Label
color='#fff'
>
<Checkbox
checked={checked}
const checkboxRow = (todo, i, checked = false) => (
<Flex
width='100%'
justifyContent='space-between'
>
<Label
color='#fff'
>
<Checkbox
checked={checked}
const revertTodo = (i) => {
const todo = completedTodos[i];
todos.unshift(todo);
setTodos(todos);
const newCompletedTodos = [...completedTodos];
newCompletedTodos.splice(i, 1);
setCompletedTodos(newCompletedTodos);
}
...
<Box width='350px'>
{todos.map((todo, i) => checkboxRow(todo, i))}
</Box>
// add this -->
<hr
color='#fff'
width='350px'
const completeTodo = (i) => {
const todo = todos[i];
completedTodos.unshift(todo);
setCompletedTodos(completedTodos);
const newTodos = [...todos];
newTodos.splice(i, 1);
setTodos(newTodos);
}
const completeTodo = (i) => {
const todo = todos[i];
completedTodos.unshift(todo);
setCompletedTodos(completedTodos);
const newTodos = [...todos];
newTodos.splice(i, 1);
setTodos(newTodos);
}
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);
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);
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);