Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants