I'm new in redux. Is it the right way to setState?
How do I setState forYou after fetching data from server?
here is my code:
const initialState={
forYou: [],
}
function rootReducer(state=initialState, action){
switch (action.type){
case 'forYou':
var url = 'http://127.0.0.1:8000/forYou/'
fetch(url, {
method: 'GET',
headers:{
'Content-Type': 'application/json',
}
}).then(res=>res.json().then(result=>{
var forYou = result
return{
...state,
forYou: forYou
}
}))
break
default:
return state;
}
}
export default rootReducer
So, what i should change?