-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove arg from usePollingValue
- Loading branch information
1 parent
d117fc2
commit 4939ba7
Showing
3 changed files
with
5 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { useRef, useReducer } from 'react'; | ||
import { expectFunction } from '@fpc/types'; | ||
|
||
const poll = ({ ref, arg }) => ({ value: ref.current.call(null, arg), ref }); | ||
const reducer = ({ ref }, arg) => poll({ ref, arg }); | ||
const evaluate = ref => ({ value: ref.current.call(null), ref }); | ||
const reducer = ({ ref }) => evaluate(ref); | ||
|
||
export const usePollingValue = (fn, arg) => { | ||
export const usePollingValue = fn => { | ||
const ref = useRef(); | ||
ref.current = expectFunction(fn); | ||
|
||
const [state, update] = useReducer(reducer, { ref, arg }, poll); | ||
const [state, update] = useReducer(reducer, ref, evaluate); | ||
|
||
return [state.value, update]; | ||
}; |