How to navigate with the react-router-dom when an action occurs

0

Hello, I'm starting to work with React and I'm doing an integration with Firebase. My problem is this, I can already trigger all the actions I need, but when I fire my last action from USUARIO_ENTRAR_SUCESSO I need to react-router-dom navigate to the /:uid route.

My reducer looks like this:

export const usuarioReducer = (state = initialState, action) => {
    switch(action.type) {
        // ...outras actions...
        case 'USUARIO_ENTRAR_SUCESSO': {
            // preciso navegar quando essa action for disparada
            return state;
        }
        default:
            return state;
    }
}

How do I do this?

    
asked by anonymous 16.06.2018 / 17:58

1 answer

1

Navigation must be done in the action itself - the reducer only changes the state of the application.

export const logar = ({
    email,
    senha
}) => {
    this.db.login(email, senha).then(res => {
        //faça a navegação por aqui
    }).catch(err => {
        //se der erro faça por aqui
    })
}
    
16.06.2018 / 23:08