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.

Implement native map and bind functions for RecoilState

See original GitHub issue

Having a correctly implemented map and bind for a type allows for very powerful abstractions and data transformations.

I have an implementation that given a recoil value it creates a selectorFamily that accepts a lifted function (via constSelector), which then fetches the dependencies, and then returns the new value.

Bind we somewhat get for free as recoil automatically flattens recoil values, so it’s the same logic as map.

I’m not terribly confident that this can’t somehow cause name conflicts at some point, and having a native implementation of these functions would be great.

I think this also ties in a bit with #314 as ideally the mapped value wouldn’t cause a re-render when the parent changes if the resulting output didn’t change (such as a simple number atom that had something like this applied: myAtom.map(x => x * 0)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
drarmstrcommented, Sep 6, 2020

@Shmew - The AST Explorer is a great tool for testing out AST rules for ESLint. The rules also need tests with ESLint Tester using Jest. The tricky part is probably just determining if we are in the context of a render function or effect. Perhaps we could start more conservatively and cover any function…

0reactions
BenjaBobscommented, Sep 6, 2020

I get where you’re coming from there, but at the same time I think it’s quite well stressed in the React documentation that calling non-hooks inside the body of your render function will not lead to a good time. So I wouldn’t expect it to be much of a surprise to anyone.

The only real point of contention here is that this will still have a performance detriment when used inside useEffect. The question then is why are they even using recoil there? You can’t share the recoil value, and they can just use useMemo for caching a transformed result.

I agree with you about the usage, I just worry that it will seem too intuitive for people to use it that way and not bother checking up on how it should actually be used. I think it should at least be addressed in the documentation then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useRecoilState(state) | Recoil
function useRecoilState<T>(state: RecoilState<T>): [T, ... This is the recommended hook to use when a component intends to read and write state.
Read more >
Ultimate 2021 Reference for React Functional Components
JSX is the HTML like syntax we can use in React Components. ... the standard way of doing so is using the array.map...
Read more >
State Management in React Native with Recoil (Part 1 - Morioh
However, sometimes you need to pack a sequential array as a MessagePack map. To do this, use the packMap method: $mpMap = $packer->packMap([1, ......
Read more >
03 React JS Tutorial 2019 State List Map Keys - YouTube
React JS TutorialIn this tutorial, I have discussed about initializing and updating state in React. Also discussed about differences between ...
Read more >
Stale-while-revalidate Data Fetching with React Hooks: A Guide
Find out how developers can use React Hooks to make this logic painlessly ... Also, we have a componentDidUpdate function, which refetches the...
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