question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dispatch triggered outside React causes N re-renders when useStoreon is used N times

See original GitHub issue

Hi,

I have an App component which uses hook A, which calls to hook B.
Both hooks are using useStoreon hook to get the same value (let’s call it items) from state.
Both hooks are simple functions without any other hooks involved. When my component is rendered, hook A gets called, then hook B and console.log I put inside component prints once. Everything is fine.

Now I create a function, which changes items in Storeon store and call that function from component outside StoreonContext.Provider wrapping App.
Every time I call that function, component’s console.log executed 2 times, indicating 2 re-renders instead of one.
I’ve noticed that if useStoreon hook is used N times, component re-renders N times.

CodeSandbox illustrating the issue: https://codesandbox.io/s/storeon-issue-n-renders-lgoxw

The same CodeSandbox, adapted to use Redux works fine: https://codesandbox.io/s/storeon-issue-n-renders-redux-ilhej

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
aicommented, Nov 16, 2019

Maybe we can ask React and Preact team for this API?

1reaction
aicommented, Oct 21, 2020

I am working on a new state manager https://github.com/logux/state

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is useReducer's dispatch causing re-renders?
The first issue is that you should never trigger any React state updates while rendering, including useReducers 's dispatch() and useState ...
Read more >
Redux: Re-rendering Caused by mapDispatchToProps
As you can see, the mapDispatchToProps takes two arguments: the dispatch function (coming from Redux) and the props being passed down into this ......
Read more >
Redux vs. Storeon: An App to App Comparison | by Kris Guzman
Redux has been the go to state management library for React apps for a long time. It's reliable, scalable, and resources are everywhere....
Read more >
Event-driven state management in React using Storeon
Events · @init – this event is fired when the application loads. It is used to set the application's initial state and executes...
Read more >
Storeon: "Redux" in 173 bytes - Evil Martians
Storeon is ready to be used in React projects or, if you care about bundle size as much as I do, with my...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found