ReactJS – Reaction Router and Flux – Clear Status

I am using flux-router and flux architecture (facebook’s flux implementation).

Currently in my system, write on my route “Chat/:topic”.

When the user enters this component, I am creating a subscription (created using the operation on componentWillMount) to the websocket server, and I am deleting the subscription on componentWillUnmount.

When the user moves to another route, the entire workflow can work normally-because react-router is uninstalling my components.

When I switch within my route (from “chat/ Game” to “Chat/TV”), the component is not installed, I need to clear the state of the component.

I read about the different actions I can take and the transition to the sending action “Transfer” and each is related The store will clear its store.

In my opinion, this behavior – is wrong, it combines my store with my router.

How would you solve this problem? Is this a question that I should ask react routers and ask them to uninstall within my route?

I found the answer thanks to gaearon( https://github.com/gaearon/), < p>

Use the store to keep the selected topic and ask the message store for the message. Nothing should be removed from the store unless it is required for performance reasons.

In my app In the program, I have to delete messages (because they are large objects) and clear my subscriptions (to reduce the load on the server).

In order to achieve this goal, I found three solutions:

p>

> Use componentWillReceiveProps and check if the parameters have been changed, whether the parameters have been changed-perform any action to clear the storage-for example call ActionCreator and reset the state.
>Send a dispose in the transition (within Router.run) The payload, it will tell all stores to clear themselves.
>The last solution (I have used) ensures that my component is uninstalled-why? Clearing the state on componentWillReceiveProps/dispose is too error-prone, just make sure to uninstall the component to make it clearer.

Detailed information on how to achieve this

https://github.com /rackt/react-router/issues/292

https://github.com/rackt/react-router/issues/496#issuecomment-64152941

I am using flux-router and flux architecture (facebook’s flux implementation).

Currently in my system, my route says “chat/:topic”.

When the user enters this component, I am creating a subscription (created using the operation on componentWillMount) to the websocket server, and I am deleting the subscription on componentWillUnmount.

When the user moves to another When there is one route, the whole workflow can work normally-because react-router is uninstalling my components.

When I switch within my route (from “chat/game” to “chat/TV” ), the component is not installed, and I need to clear the state of the component.

I read about the different actions I can take and the transition to the sending action “transfer” and each related store will clear its store.< /p>

In my opinion, this behavior-is wrong, it combines my store with my router.

How would you solve this problem? Is this a question that I should ask react routers and ask them to uninstall within my route?

I found the answer thanks to gaearon (https://github.com/gaearon/),

Use store reservation Select the topic and ask the message store for the message, nothing should be deleted from the store unless needed for performance reasons.

In my application, I have to delete messages (because they are large Object) and clear my subscription (to reduce the load on the server).

In order to achieve this, I found three solutions:

>Use componentWillReceiveProps and check whether the parameters Changed, whether to change the parameters-perform any action to clear the storage-for example call ActionCreator and reset the state.
>In the transition (within Router.run) send a dispose payload and it will tell all stores to clear themselves.
> br>>The last solution (I have used) to ensure that my component is uninstalled-why? Clearing the state on componentWillReceiveProps/dispose is too error-prone, just make sure to uninstall the component to make it clearer.

Detailed information on how to achieve this

https://github.com /rackt/react-router/issues/292

https://github.com/rackt/react-router/issues/496#issuecomment-64152941

< /p>

Leave a Comment

Your email address will not be published.