Question: Fetch atoms/selectors via "key"?
See original GitHub issueAccording to the docs, each atom/selector need to be given a unique key
. Is it possible/planned to get an atom/selector by this key? If not, is there a way the library could generate a unique key without forcing the user to provide it?
// ...somewhere in the app...
const tempFahrenheit = atom({
key: 'tempFahrenheit',
default: 32,
});
//
const [tempF, setTempF] = useRecoilState('tempFahrenheit');
Just trying to get a better understanding of the library. Thanks 😃
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Retrieve an atom/selector by key (string)? - Stack Overflow
No it's not possible. The value that the call to atom() returns is a reference to the state, that the useRecoil... hooks need...
Read more >selector(options) - Recoil
get () - a function used to retrieve values from other atoms/selectors. All atoms/selectors passed to this function will be implicitly added to...
Read more >Lessons learned from moving to Recoil.js - Kitemaker blog
A selector is a derived piece of state. It fetches data from atoms (or other selectors), and transforms them in some way. An...
Read more >Get started with Recoil by building a Fantasy app in React ...
Selectors are pure functions, that consume atoms (or other selectors), process the data, and return it. They are used to create derivative data....
Read more >How to Manage Your React Application State With Recoil.js ...
A selector is an object which represents a piece of derived state. Any given selector is subscribed to a Recoil atom. Whenever that...
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 FreeTop 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
Top GitHub Comments
We’ve discussed this internally. There were some proposals to add Recoil “zones/contexts”, which would help solve the key namespace concern and help with composability. Though, this isn’t the highest priority at the moment. In the meantime, we use conventions for namespacing keys, e.g.
'Module/Key'
.No current plans to allow non-opaque strings as atom/selector handles in the API. Generally we want to enforce that you’re actually working with the same shared atom/selector, provide protection from string typos, etc. It has worked pretty well to export shared atoms/selectors from shared modules that can be imported from the components or selectors that need them.
Don’t like fetch by key because could lead to weird behaviour where the
atom
itself isn’t included in the bundle because no-one imports it because it’s just being referenced by key name.