question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add utility functions: useFocusAtom, useSelectValue

See original GitHub issue

Instead 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:closed
  • Created 2 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
LuckyPigeoncommented, Oct 19, 2021

@dai-shi I think I can support the documentation, let me do some research first.

0reactions
dai-shicommented, Jan 4, 2022

closed by #923

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found