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

Documentation: atomFamily with parameterized default value #2286

Open
SlowSnowFox opened this issue Sep 11, 2023 · 0 comments
Open

Documentation: atomFamily with parameterized default value #2286

SlowSnowFox opened this issue Sep 11, 2023 · 0 comments

Comments

@SlowSnowFox
Copy link

According to https://recoiljs.org/docs/api-reference/utils/atomFamily/#parameter-type it is possible to provide a function as default to an atomFamily like this:
const myAtomFamily = atomFamily({ key: ‘MyAtom’, default: param => defaultBasedOnParam(param), });
If I want to fetch a specific atom from the family (or create a new one if it doesn't exist) I can do so like this:
useRecoilState(myAtomFamily(myId));
How can I do the above and provide the param to the default function? From the documentation, this is not clear. (I also tried various combinations and was not successful)
I expected something like this but it just errors out:
useRecoilState(myAtomFamily(myId, myValueToTheDefaultFunction));

I'm happy to create a PR for updating the documentation if I get a working example.

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

1 participant