H
H
Hlib2019-06-16 22:38:04
React
Hlib, 2019-06-16 22:38:04

How to get data from reudx asynchronously?

We have an authorization field with success data in the redux state, after clicking the button, the backend, depending on the entered data, will send success: true or success: false
The fact is that when I write to the connect state a variable that I take from reudx , it doesn't get updated when data is updated in redux.
Is it possible to somehow take data from redux with an action or in another way?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2019-06-16
@Mysianio

1. In the action, change the line:
2. In the reducer:

case 'LOGIN_USER_SUCCESS':
  return {
    ...state,
    key: action.key, 
  };

3.connect:
const mapStateToProps = state => ({
  success: state.authorisation.key,
});

export default connect(mapStateToProps)(YourComponent);

In a good way to fix:
authorisation ----> authori z ation

V
Vladimir, 2019-06-17
@Casufi

Seems you need to look at https://github.com/reduxjs/redux-thunk

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question