-
-
Notifications
You must be signed in to change notification settings - Fork 700
feat: add unstable_defaultUse
#3111
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import { Component, StrictMode, Suspense } from 'react' | ||
| import { Component, StrictMode, Suspense, use } from 'react' | ||
| import type { ReactNode } from 'react' | ||
| import { act, render, screen } from '@testing-library/react' | ||
| import userEvent from '@testing-library/user-event' | ||
| import { expect, it } from 'vitest' | ||
| import { expect, expectTypeOf, it } from 'vitest' | ||
| import { useAtomValue, useSetAtom } from 'jotai/react' | ||
| import { atom } from 'jotai/vanilla' | ||
|
|
||
|
|
@@ -120,3 +120,24 @@ | |
|
|
||
| expect(await screen.findByText('obj: 1,2')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('useAtomValue with unstable_defaultUse', async () => { | ||
| const numberAtom = atom(Promise.resolve(1 as const)) | ||
|
|
||
| const ObjComponent = () => { | ||
| const value = useAtomValue(numberAtom, { unstable_defaultUse: false }) | ||
| expectTypeOf(value).toEqualTypeOf<Promise<1>>() | ||
|
|
||
|
Check failure on line 130 in tests/react/useAtomValue.test.tsx
|
||
| return <div>number: {use(value)}</div> | ||
|
Check failure on line 131 in tests/react/useAtomValue.test.tsx
|
||
| } | ||
|
|
||
| await act(() => | ||
| render( | ||
| <StrictMode> | ||
| <ObjComponent /> | ||
| </StrictMode>, | ||
| ), | ||
| ) | ||
|
|
||
| expect(await screen.findByText('number: 1')).toBeInTheDocument() | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should warn if it's undefined for the migration. So, it's too early to merge this PR.