Jotai and Zustand together: Chat with ChatGPT

is it wise to use jotai and zustand together?

Using Jotai and Zustand together can be beneficial, depending on your application's needs. Both libraries are lightweight state management solutions, but they serve slightly different purposes:

When to Use Both Together

Things to Consider

Conclusion

If your application requires both fine-grained state control and broader global state management, using Jotai and Zustand together can be a wise choice. Just be mindful of the added complexity and ensure that it’s necessary for your specific use case.

give me a size comparison of using the two together vs using redux with redux toolkit

When comparing the size of using Jotai and Zustand together versus using Redux with Redux Toolkit, here’s a general overview:

Bundle Size Overview (self research with Bundlephobia and GPT)

Zustand

Pasted image 20240902192134.png

Jotai

Pasted image 20240902192154.png

redux

Pasted image 20240902192208.png

redux toolkit

Pasted image 20240902192311.png

react-redux

Pasted image 20240902192346.png

GPT's answer

  1. Zustand + Jotai:

    • Zustand: Around 2 KB minified + gzipped.
    • Jotai: Around 3.5 KB minified + gzipped.
    • Combined: Approximately 5.5 KB minified + gzipped.
  2. Redux + Redux Toolkit:

    • Redux: Around 6.7 KB minified + gzipped.
    • Redux Toolkit: Adds around 8 KB minified + gzipped.
    • Combined: Approximately 14.7 KB minified + gzipped.

Comparison

Considerations Beyond Size

Conclusion

Using Jotai and Zustand together results in a smaller bundle size compared to using Redux with Redux Toolkit. If bundle size is a priority and your application doesn't require the full feature set of Redux, the Jotai + Zustand combination could be a more efficient choice. However, if you need the advanced features and ecosystem that Redux offers, the larger size might be justified.