Skip to content

Commit

Permalink
🐛 Bug Fix!
Browse files Browse the repository at this point in the history
Sometimes when you attempt to sync a large amount of components at once, some of them gets ignored and won't be affected.
This is due the fact we're using a loop to call render() on each one of them, and this could go so fast the way that react cannot handle all of these updates.
A good solution would be wrapping render() inside a timeout just like that: setTimeout(() => render(), 0).
  • Loading branch information
iMrDJAi committed Sep 20, 2021
1 parent cca97cb commit 53e7ce3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "usesync",
"version": "1.0.0",
"version": "1.1.0",
"description": "A custom React hook to synchronize and share public state across different components on your React project",
"main": "src/useSync.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/useSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var useSync = id => {
}

var sync = id => {
if (syncs[id]) for (let render of syncs[id]) render()
if (syncs[id]) for (let render of syncs[id]) setTimeout(() => render(), 0)
}

var storage = {}
Expand Down

0 comments on commit 53e7ce3

Please sign in to comment.