A
A
Alexander Kusak2019-06-28 22:04:30
React
Alexander Kusak, 2019-06-28 22:04:30

How to change state outside React components?

I am developing an application and I should receive data from the server that needs to be updated outside the components, i.e. directly in the state. State, in turn, is formed from several state reducer modules (I use combineReducers to merge them).

How can this be done at the window object level? If it is not possible to wait for a response after a request from the component (the request is not sent like an axios promise, in the code you only need to wait for a response that will call the method and change the state).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2019-06-28
@McFree

the question is kind of strange, you take a fetch, you get an answer, you dispatch an action with the result, and you have data in the store, your components are subscribed to the store and map its pieces to the props of your component, then auto-render

var action = {
  type: 'ADD_USER',
  user: {name: 'Dan'}
};

// Assuming a store object has been created already
store.dispatch(action);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question