Skip to content

Commit

Permalink
🐛 Prevent overriding initialValue by undefined when not passing a new…
Browse files Browse the repository at this point in the history
…Value to sync()
  • Loading branch information
iMrDJAi authored May 17, 2022
1 parent 4611cce commit 1bf3f06
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 1bf3f06

Please sign in to comment.