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(examples, tests): use useUpdateAtom and write-only atoms to avoid re-render #598

Merged
merged 1 commit into from
Jul 17, 2021

Conversation

liby
Copy link
Contributor

@liby liby commented Jul 16, 2021

Response to the call for this issue

The utility hooks can get big. I need someone to volunteer to help it, especially for documentation & examples.

@vercel
Copy link

vercel bot commented Jul 16, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pmndrs/jotai/AxkR7Aa5QqLHeU91FBcuJ3LwdeUU
✅ Preview: https://jotai-git-fork-liby-master-pmndrs.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 16, 2021

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 d8c400e:

Sandbox Source
React Configuration
React Typescript Configuration

@dai-shi
Copy link
Member

dai-shi commented Jul 16, 2021

Thanks for your help.
Having best practices in examples is nice.
Using utils in utils tests is ok.

However, I would like to keep tests/*.test.tsx to depend only on core (no utils).
It's intentional/acceptable to have extra re-renders there (not important for tests).
If it were issues, we would make write-only atoms (that's the suggestion for core-only solution).

If you can adjust it, please go ahead. I can take it over if you like.

@dai-shi dai-shi changed the title fix: use useUpdateAtom to avoid re-render fix(examples, tests): use useUpdateAtom to avoid re-render Jul 16, 2021
@liby
Copy link
Contributor Author

liby commented Jul 17, 2021

@dai-shi
I've revised it. Could you take another review of it for me?

It's intentional/acceptable to have extra re-renders there (not important for tests).
If it were issues, we would make write-only atoms (that's the suggestion for core-only solution).

If necessary, I can undo changes other than utils tests and examples.

@liby liby changed the title fix(examples, tests): use useUpdateAtom to avoid re-render fix(examples, tests): use useUpdateAtom and write-only atoms to avoid re-render Jul 17, 2021
Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. As I said, I don't think it's very important to avoid re-renders in some of core tests, but someone may learn coding pattern from tests, so it'd be good as you suggest.

tests/items.test.tsx Outdated Show resolved Hide resolved
@liby
Copy link
Contributor Author

liby commented Jul 17, 2021

but someone may learn coding pattern from tests

Yes, that's why I kept the comments in the sample code.

@dai-shi dai-shi merged commit 58d056c into pmndrs:master Jul 17, 2021
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