Created
March 4, 2025 10:58
-
-
Save kaineer/dbc5f18d9b49a6b57352923c7d28a13f to your computer and use it in GitHub Desktop.
main-component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
import { useState, useEffect } from 'react'; | |
import { useSelector, useDispatch } from 'react-redux'; | |
import { NewTask } from './NewTask' | |
import { TaskList } from './TaskList' | |
import { TodosSlice } from '../../slices/todo'; | |
export const Todos = () => { | |
const { | |
selectors: { getTasks }, | |
actions: { setTasks }, | |
} = TodosSlice; | |
const dispatch = useDispatch(); | |
const tasks = useSelector(getTasks); | |
useEffect(() => { | |
if (!tasks || tasks.length < 1) { | |
fetch('http://localhost:3000/tasks'). | |
then((resp) => resp.json()). | |
then((data) => dispatch(setTasks(tasks))); | |
} | |
}, []); | |
return ( | |
<> | |
<NewTask /> | |
<TaskList /> | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment