I just wanna know is it possible to use useReducer, as I use it inside UseEffect fetched data => State => useReducer(..., State)
const [initialData, setInitialData] = useState({ name: 'ass' });
const [data, dispatch] = useReducer(apiReducer, initialData);
const Data2 = useFetch('/qaz')
useEffect(() => {
setInitialData(Data2)
}, [Data2])
useEffect(() => {
dispatch({ type: 'Different', payload: 'key' })
}, [initialData])
export function apiReducer(state, action) {
switch (action.type) {
case 'Different':
return { ...state, key: action.payload };
default:
return state
}
}