Skip to content

Commit

Permalink
Merge pull request #2 from iMrDJAi/fix
Browse files Browse the repository at this point in the history
🐛 Prevent overriding initialValue by undefined when not passing a newValue to sync()
  • Loading branch information
iMrDJAi authored May 18, 2022
2 parents 4611cce + 1bf3f06 commit 20e6323
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 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": "2.0.0",
"version": "2.0.1",
"description": "A subscription based state management solution for React!",
"main": "src/useSync.js",
"type": "module",
Expand Down
5 changes: 3 additions & 2 deletions src/useSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const syncs = {}
const useSync = (id, initialValue) => {
const [, dispatch] = useReducer(state => !state, false)
const value = useRef(initialValue)
const render = (newValue) => {
value.current = newValue
const render = (...args) => {
const [newValue] = args
if (args.length) value.current = newValue
dispatch()
}

Expand Down

0 comments on commit 20e6323

Please sign in to comment.