Answer the question
In order to leave comments, you need to log in
Object not added to array?
Reducer loggedReducer:
export default function loggedReducer(state=[], action) {
switch(action.type) {
case 'SIGN_IN':
return state.push(action.payload);
case 'LOG_OUT':
return state = [];
default:
return state;
}
}
const dispatch = useDispatch();
React.useEffect(() => {
async function fetch() {
const {data} = await axios.get('/profile/api/user');
dispatch(signIn(data));
setUser(data);
}
fetch();
}, [dispatch]);
export const signIn = (user) => {
return {
type: 'SIGN_IN',
payload: user
}
}
import loggedReducer from './isLogged.js';
import {combineReducers} from 'redux';
const allReducers = combineReducers({
logged: loggedReducer
})
export default allReducers;
const logged = useSelector(state => state.logged);
const dispatch = useDispatch();
console.log('logged: ' + logged); // 1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question