best practise using jotai in big project?
See original GitHub issueNow I just treat jotai as state management tool, but I think jotai can do more than that. I read the docs, and noticed that maybe I can write my logic in the derived atom and I don’t need to put them in custom hooks anymore.
simply like this:
const countAtom = atom(1)
const asyncIncrementAtom = atom(null, async (get, set) => {
// await something
set(countAtom, get(countAtom) + 1)
})
const Component = () => {
const [, increment] = useAtom(asyncIncrementAtom)
// it will suspend while `increment` is pending.
}
but then my question is, how should I organize the atom structure? should I put theme together or split them into serval files? when should I use atom, and when shouldn’t I use it?
all the examples in the doc is too simple. Is there any best practices to demonstate the best way of using jotai?
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Jotai: The Ultimate React State Management
Jotai is a relatively new state management library for React. It's simple, but make no mistakes, it's a robust library. Jotai is based...
Read more >A Guide to Jotai: the Minimalist React State Management ...
How to manage global state in React using the minimalist but flexible Jotai library.
Read more >Manage the state of your React app with Jotai
Manage the state of your React app with Jotai ... Managing the global state of a web application is one of the biggest...
Read more >Jotai: Atom-based state management for React
Jotai compared with Recoil, Zustand, and Redux. Many state management tools are available for React now, and most of them fall under a ......
Read more >Redux-Free State Management with Jotai
Both Jotai and Recoil are great examples of how hooks have influenced React application development. Redux has been the most well-known ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dai-shi maybe it’s better to transform this issue to discuss.
I didn’t get a good idea about dealing with other hooks from third-party libraries, such as react-navigation. for example, I need to do some logic and then navigate to other screens. I can use
const navigation = useNavigation()
whichuseNavigation
is a custom hook fromreact-navigation
library. I can do this in custom hooks, but as we discussed above, If we write all these logic in derived atoms, how can I do that? because Hooks can only be used in hooks.