using Context Api how to set initial state

795 views Asked by At

I am fetching data from http://127.0.0.1:8000/api/todos receiving array using app level state how should i populate the initial state in Context API ?

    const initialState={
        todos:[]
        ,
         current:null

    }

    const [state, dispatch] = useReducer(Todoreducer, initialState)

    fetch('http://127.0.0.1:8000/api/todos')
    .then(data => data.json())
    .then(  res =>
        // console.log(res)
        state.todos= res
        )
enter image description here in this i am not getting state to other components but state is available in TodoState in React Tools

0

There are 0 answers