question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

best practise using jotai in big project?

See original GitHub issue

Now 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:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
chj-damoncommented, Dec 17, 2021

@dai-shi maybe it’s better to transform this issue to discuss.

0reactions
chj-damoncommented, Dec 17, 2021

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() which useNavigation is a custom hook from react-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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found