Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Selector-like hook for components #2303

Open
derolf opened this issue Jan 29, 2024 · 2 comments
Open

Feature request: Selector-like hook for components #2303

derolf opened this issue Jan 29, 2024 · 2 comments

Comments

@derolf
Copy link

derolf commented Jan 29, 2024

Imagine we had

const [get, getCallback] = useRecoil();

where get and getCallback have the same semantics as in the getter of selector.

Then I could write:

function Foo() {
  const [get, getCallback] = useRecoil();
  return <>{get(myAtom)} <button onClick={() => getCallback(({i}) => i.set(myAtom, 42))}>42</button></>
} 
@derolf derolf changed the title Feature request: Selector-like components Feature request: Selector-like hook for components Jan 29, 2024
@suren-atoyan
Copy link

what was the motivation behind this?

@derolf
Copy link
Author

derolf commented Jan 30, 2024

The motivation is to avoid value/state-hooks for every piece the component is using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants