Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent map re-rendering on update with Redux subscription #445

Closed
llanginger opened this issue Mar 8, 2017 · 8 comments
Closed

Prevent map re-rendering on update with Redux subscription #445

llanginger opened this issue Mar 8, 2017 · 8 comments

Comments

@llanginger
Copy link

Hi there,

I imagine there is a way of doing this that is easy and obvious that I have not seen. I would like to use this package in a redux app I am building but I am having trouble with the map re-rendering any time I update my store (which, being a redux app, is basically any time anything changes). There was a suggestion in another issue to use componentShouldUpdate(...){ return false } but this appears not to be of use here as redux's subscribe uses forceUpdate() which specifically circumvents componentShouldUpdate.

Any thoughts would be appreciated!

@aaronofleonard
Copy link

It is true that Redux does use forceUpdate, however it only forces and update on the HOC, the "outer component" that is wrapping the real component. Therefore, even if the outer component that's connected to the state forces an update, it doesn't mean that shouldComponentUpdate (not componentShouldUpdate) gets skipped. Using shouldComponentUpdate will still cause the base component to perform the check before updating.

Reference:
https://facebook.github.io/react/docs/react-component.html#forceupdate
"This will trigger the normal lifecycle methods for child components, including the shouldComponentUpdate() method of each child."

@tomchentw
Copy link
Owner

Please refer to Getting Help section in the README (or #469).

@basvdheijden
Copy link

I've searched stackoverflow, but couldn't find an answer. Care to elaborate on a solution @aaronofleonard ?

@aaronofleonard
Copy link

The answer is just use shouldComponentUpdate. As I brought out, Redux does use forceUpdate, but that does not circumvent shouldComponentUpdate inside your components. It only executes forceUpdate on the outer component that Redux makes and manages. Use shouldComponentUpdate, problem solved!

@jojo-tutor
Copy link

jojo-tutor commented Feb 24, 2018

@aaronofleonard , This does not resolve the issue. What if I have list of Map Markers that are dependent on the global state/redux ? I want to update my Map but re-rendering the Map has this 'flicker' side-effect. How to solve this issue ?

@yuracherkasov
Copy link

I saved location data in the local State. In my case, this problem was solved.

@jojo-tutor
Copy link

@yuracherkasov , i'm aware of that but my situation is different, i must listen to socket for changes in the list of markers.

@nancy0507
Copy link

@jojo-tutor I am facing the same issue, anybody found solution for above. I have a websocket connection from where i am continuously getting lat lng, I am not even updating the center but it is updating the center as soon as any event is received and causing flickering issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants