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

fix: lazyMap on atomWithLazy #2493

Closed
wants to merge 2 commits into from

Conversation

himself65
Copy link
Collaborator

Related Issues or Discussions

Fixes #2465 (comment)

Summary

Check List

  • yarn run prettier for formatting code and docs

Copy link

vercel bot commented Apr 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jotai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 8, 2024 7:29pm

Copy link

codesandbox-ci bot commented Apr 8, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

github-actions bot commented Apr 8, 2024

LiveCodes Preview in LiveCodes

Latest commit: a4a304e
Last updated: Apr 8, 2024 7:29pm (UTC)

Playground Link
React demo https://livecodes.io?x=id/6KXVQB78W

See documentations for usage instructions.

@dai-shi
Copy link
Member

dai-shi commented Apr 9, 2024

It's the motivation and the requirement to initialize for each store.

We can use `atomWithLazy` to create a primitive atom whose initial value will be computed at [first use in the store](#using-multiple-stores).

@dai-shi dai-shi closed this Apr 9, 2024
@dai-shi
Copy link
Member

dai-shi commented Apr 9, 2024

In case, one wants to share data, they could do something like this:

let initializedData;
const dataAtom = atomWithLazy(() => (initializedData ??= Date.now()));

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

Successfully merging this pull request may close these issues.

2 participants