useInitialValue util
See original GitHub issueI’m trying to learn jotai, it’s great. I’m trying to write a custom hook that will only get the initial value and not re-render on consquent updates. I tried this which obviously doesn’t work. Any tips on how I can accomplish this? Just a learning thing.
function useInitialValueAtom(atom) {
const [value] = useAtom(atom);
const savedValue = useRef(value);
return savedValue.current;
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
rrRoadRunner — libRoadRunner 1.1.16 documentation
useInitialValue – a boolean value to indicate whether using initial value as current value when the assignment rule of a variable is removed...
Read more >initialValues - React Advanced Form - GitBook
An object that describes initial values of the fields. Definition.
Read more >ariakit-utils v0.17.0-next.26 Bundlephobia
Size of ariakit-utils v0.17.0-next.26 is 18.5 kB (minified), and 5.7 kB when compressed using GZIP. Bundlephobia helps you find the performance impact of ......
Read more >Auto Complete Text Box - TechDocs
Always Use Initial Value. Sets whether the initial value is always displayed upon first entering the form. Escape HTML. Sets whether the component...
Read more >@angular/common | Yarn - Package Manager
72092ebd26, feat, Allow a FormControl to use initial value as default. ... /packages/compiler/src/render3/view/util.ts#L174-L206; language-service: resolve ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Noitidart I don’t think so, I loved your idea + @merisbahti solution, @dai-shi What’s your opinion about adding something like this to the utils?
@Noitidart Thanks for the use case. RHF is nice for uncontrolled forms.
So, conceptually, the default value and the current value have different values. How about something like this?
I think having atom values in ref out of sync is not React-ish, and better to avoid it.