-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
docs(performance): new section #1208
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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 43019bf:
|
Hi, thanks for the suggestion and your work. Let's spend time on this. I will think about it and let you know the basic idea. I'm sure you will be able to extend it and write a great guide. |
@dai-shi Yeah sure, forgot to set it as draft, but it's totally a first step. I need help to know if I'm going on the good way. Looking forward to discuss that with you. Gonna bring some changes from time to time until we get something decent. We're in no rush to have this new page ;) Also probably the topic that most interests me! |
Here's rough idea how I would like to have jotai performance guide to be. Jotai performance guideOptimizing re-renderAtoms are the unit of triggering re-renders, so atoms should be small enough to reduce extra re-renders// bad practice
const objAtom = atom({ x: 0, y: 0 })
const Component1 = () => {
const [value, setValue] = useAtom(objAtom) // this will trigger re-renders either `x` or `y` changes
...
}
// good practice
const xAtom = atom(0)
const yAtom = atom(0)
const Component2 = () => {
const [x, setX] = useAtom(xAtom)
const [y, setY] = useAtom(yAtom)
...
} That's general guideline, but there are exceptions. If you always use Likewise, derived atoms (custom
|
@@ -104,8 +104,9 @@ Then we use it in our component: | |||
import { atom, useAtom } from 'jotai' | |||
import { selectAtom, splitAtom } from 'jotai/utils' | |||
|
|||
const Tags: React.FC = () => { | |||
const tagsAtom = selectAtom(readOnlyInfoAtom, (s) => s.tags) | |||
const selector = (s) => s.tags |
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.
const selector = (s) => s.tags | |
const selectTags = (s) => s.tags |
How's this?
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.
@dai-shi Yeah or tagsSelector, both ok to me
This reverts commit c3b7324.
While this guide is still fairly WIP, let's merge it and get feedback. |
Following-up of this issue, we decided to: