N
N
nemoisfree2017-06-17 19:53:16
JavaScript
nemoisfree, 2017-06-17 19:53:16

Is it possible to decorate redux connect or how to unsubscribe from redux store?

Passing props (storeName) to the component in the component I would like to subscribe to the store with the name I passed i.e. (this.props.reducerName) for an example of how I would like it to look
<MyComponent reducerName="city" />

export default connect(state => ({
    some: state[this.props.reducerName]
}), { })(MyComponent);

Is it possible to decorate redux connect somehow? By passing this.props.reducerName into it somehow
I tried to go the other way and used store.subscribe
componentDidMount() {
    store.subscribe(() => {
        this.setState({some: store.getState([this.props.reducerName]});
    });
}

But when I switch to another route, I see the error
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op.
How to unsubscribe from redux store when uninstalled?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2017-06-17
@maxfarseer

I don't know why, but to the question "How to unsubscribe from the redux store when dismantled?" easy to answer - use componentWillUnmount
ps worth reading in full - the component lifecycle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question