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

utils bundle and use update atom #35

Merged
merged 2 commits into from
Sep 13, 2020
Merged

utils bundle and use update atom #35

merged 2 commits into from
Sep 13, 2020

Conversation

dai-shi
Copy link
Member

@dai-shi dai-shi commented Sep 13, 2020

ref: #26

This adds new utils bundle, that is separated from core.

import { atom, useAtom } from 'jotai'
import { useUpdateAtom } from 'jotai/utils'

const countAtom = atom(0)

const Counter = () => {
  const [count] = useAtom(countAtom)
  return <div>count: {count}</div>
}

const Controls = () => {
  const setCount = useUpdateAtom(countAtom)
  const inc = () => setCount(c => c + 1)
  return <button onClick={inc}>+1</button>
}

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 13, 2020

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.

Latest deployment of this branch, based on commit 9a8e7af:

Sandbox Source
React Configuration
React Typescript Configuration

@dai-shi
Copy link
Member Author

dai-shi commented Sep 13, 2020

https://codesandbox.io/s/react-typescript-forked-3q11k
Working as expected.

@dai-shi dai-shi merged commit 9127e2f into master Sep 13, 2020
@dai-shi dai-shi deleted the use-update-atom branch September 13, 2020 08:26
This was referenced Sep 13, 2020
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.

1 participant