Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Use Async Functions in a Recoil Selector


    Instead of just returning a value from a recoil selector, you can return any promise, which means that you can do asynchronous functions in recoil selectors (this is a little like a redux thunk).

    The huge bonus is that you don't have to do anything different when actually calling the selector - use can use useRecoilValue in the same way that you would from a normal selector.

    The only thing you must do is somewhere in the component tree, wrap any component that uses an async selector with a <React.Suspense> tag with a fallback prop that will tell React what to display when the async selector isn't loaded yet.