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.

Question: Fetch atoms/selectors via "key"?

See original GitHub issue

According 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
drarmstrcommented, May 27, 2020

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.

1reaction
ShanonJacksoncommented, May 29, 2020

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.

Read more comments on GitHub >

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

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