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.

Jotai for libraries

See original GitHub issue

As a library author, I want to make sure the values of the atoms my library relies upon are only updated in the jotai.Providers I control and not the ones, the users of my library might add to the tree for their own purposes.

I believe we need some API in jotai to support it. The initial discussion happened here

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
youknowriadcommented, Nov 13, 2020

Hey there!

First, thank you for jotai, it’s an amazing library and learned a lot from it.

For context, I work on the WordPress block editor and we have a data layer package called @wordpress/data that relies mostly on Redux stores with some specifics. We faced performance issues while rendering a lot of components and we started exploring alternatives. Right now we are considering a solution based on atoms like Recoil and Jotai.

I’d have loved to be able to use Jotai directly, unfortunately, the specifics of the data module don’t allow that. We need a library that is fundamentally React agnostic, and we also need something that can work in multiple registries/scopes (and that’s why I’m commenting here).

I’m not sure if it’s any helpful but I wanted to share this very experimental PR I’m currently working on https://github.com/WordPress/gutenberg/pull/26866 which creates that (a framework and scope agnostic alternative to Recoil and Jotai). My approach there was to use “registries” (though I like the proposed name here “scope”).

1reaction
dai-shicommented, Nov 15, 2020

A little bit of extra thing to always keep in mind that you need to set scope for each atom you are creating but most of the libraries

@vovacodes I’m expecting a lib author to create its own wrapper, something like this:

import { atom as atomOrig } from 'jotai'

const myScope = Symbol()
export atom = (read, write) => {
  const anAtom = atomOrig(read, write)
  anAtom.scope = myScope
  return anAtom
}

I think Jotai would benefit from having a vanilla bundle like Zustand.

@mdingena @youknowriad Actually, it might be a good idea to keep the core code cleaner. I’m still working on refactoring core. However, the vanilla bundle might not be very useful as is, because it would be an unusual api to support React Concurrent Mode.

(tbh, I’m not so keen to provide framework-agnostic version of atom state management, just because there are already many: mobx, reatom or naive observables)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jotai, primitive and flexible state management for React
Jotai takes a bottom-up approach to React state management with an atomic model ... libraries such as atomWithStore which is bound with a...
Read more >
A Guide to Jotai: the Minimalist React State Management Library
How to manage global state in React using the minimalist but flexible Jotai library.
Read more >
Jotai — new state management library for React - Medium
Jotai. Recently I found this new state management library for react applications. Primitive and flexible state management library for React.
Read more >
Jotai: The Ultimate React State Management - 100ms
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 >
Jotai React - Best Global State Library - YouTube
Learn Jotai React library which is a simple solution for sharing global state in React applications. It is a nice alternative to useState, ......
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