S
S
Stepan2016-02-02 17:51:31
JavaScript
Stepan, 2016-02-02 17:51:31

How to listen to the store and re-render the component?

There is a component that changes store.
Specifically, this is a component that listens to resize and, depending on the changes, calls dispatch.
There is another component that is not related to this in any way. Or rather, Resize is rendered in my component.
I need to change state by changing dispatch.
The structure is like this

<Modal>   <-- тут надо отслеживать изменения
<Resize />   <-- тут происходит изменения store 
</Modal>

I tried to pass something like onResize, it turns out either a cycle, or is not a function. If in onResiae do not change store

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman_Kh, 2016-02-02
@Roman_Kh

From your component, you should never call dispatch at all.
In Resize you must call action which calls dispatch.
When the store performs an update, it should send a message, say, RESIZE
Quite apart from this, the Modal should, when created (for example, in componentDidMount ), subscribe to receive RESIZE messages from the store.
Upon receiving a message, Modal must respond to it, for example by calling render, changing its state via setState or via forceUpdate().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question