-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from 92green/feature/fix-length-resize
Fix length-based resize, add set() debounce, add useProps()
- Loading branch information
Showing
14 changed files
with
318 additions
and
41 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
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
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {useState, useCallback} from 'react'; | ||
import type {Dendriform} from './Dendriform'; | ||
|
||
type UsePropsResult<V> = { | ||
value: V, | ||
onChange: (newValue: V) => void | ||
}; | ||
|
||
export const useProps = <V,C>(form: Dendriform<V,C>, debounce = 0): UsePropsResult<V> => { | ||
const formValue = form.useValue(); | ||
const [lastFormValue, setLastFormValue] = useState(formValue); | ||
const [localValue, setLocalValue] = useState(formValue); | ||
|
||
if(formValue !== lastFormValue) { | ||
setLastFormValue(formValue); | ||
setLocalValue(formValue); | ||
} | ||
|
||
const onChange = useCallback((newValue: V) => { | ||
setLocalValue(newValue); | ||
form.set(newValue, debounce); | ||
}, []); | ||
|
||
return { | ||
value: localValue, | ||
onChange | ||
}; | ||
}; |
Oops, something went wrong.