Add utility functions: useFocusAtom, useSelectValue
See original GitHub issueInstead of wrapping focusAtom
with useAtom
, and selectAtom
with useAtomValue
, I think the following would be nice:
useFocusAtom
import { useFocusAtom } from "jotai/optics";
function SomeComponent(props) {
const [z, setZ] = useFocusAtom(x, (y) => y.prop("someKey"))
return <></>
}
useSelectValue
import { useSelectValue } from "jotai/utils";
function SomeComponent(props) {
const z = useSelectValue(x, (y) => y.someKey))
return <></>
}
I guess the implementations would be something like this:
export function useFocusAtom(anAtom, keyFn) {
return useAtom(focusAtom(anAtom, keyFn))
}
export function useSelectValue(anAtom, keyFn) {
return useAtomValue(selectValue(anAtom, keyFn))
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (14 by maintainers)
Top Results From Across the Web
Custom useAtom hooks - Jotai
Custom useAtom hooks. This page shows the ways of creating different utility functions. Utility functions save your time on coding, and you can...
Read more >Javascript Utility Functions Explained Simply - YouTube
A utility function is a standalone function that does not have any side effects and whose output is directly dependent on it's input....
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
@dai-shi I think I can support the documentation, let me do some research first.
closed by #923