How to navigate with React-router-dom when an action occurs

Asked

Viewed 116 times

0

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

My brother is 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 that?

  • Reducer should never interact this way with the application! All navigation should be done through the actions, Reducer only changes the state.

  • means then that instead of me calling the Reducer, I can simply fire an action?

1 answer

1

Navigation must be done in the action itself - the Reset 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
    })
}
  • Got it, in this case then how do I call the Actionscript’s React-router-dom?

  • Unfortunately, I don’t know how to work with Reset-router-dom for navigation, so I don’t know how to answer you in this sense. I use React-Native-router-Flux to navigate between pages.

  • I’ll read about it... There’s some reference there

  • The documentation itself is more than necessary to start using it, it is very simple to use. link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.