A
A
Alexey Yakovlev2021-07-29 13:12:13
redux
Alexey Yakovlev, 2021-07-29 13:12:13

The value for the user changes, what's wrong?

action:

export const login = () => {
    return {
        type: 'LOGIN'
    }
}


reducer:
const user = (state = false, action) => {
    switch(action.type) {
        case 'LOGIN':
            return !state;
        default:
            return state;
    }
}

export default user;


all reducers:
import { combineReducers } from 'redux';
import user from './user.js';

const allReducers = combineReducers({
    user
})

export default allReducers;


so I change the user value totrue
onSubmit={() => dispatch(login())}
<form onSubmit={() => dispatch(login())} className="auth__content-form" action="/auth/login" method="POST">
    <input type="email" placeholder="Электронная почта" name="email" required />
    <input type="password" placeholder="Пароль" name="password" required />
    <input type="submit" value="Войти" />
</form>


After that, the user's state changes, but after a reboot it becomesfalse

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
black1277, 2021-07-29
@black1277

Well, cancel the reboot. In the onSubmit event, accept the event argument and call event.preventDefault()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question