Recoil 0.7.1
Typing
- Add explicit and required
children
prop to<RecoilRoot>
anduseRecoilBridgeAcrossReactRoots_UNSTABLE()
for TypeScript to support the removal of implicit children with `@types/[email protected]^18.0.0 for React 18. (#1718, #1717, #1726, #1731) - Update typing for family parameters to better support Map, Set, and classes with
toJSON()
. (#1709, #1703)
Fixes
- Avoid dev-mode console error with React 18 when using shared async selectors across multiple
<RecoilRoot>
's. (#1712) - Cleanup potential memory leak when using async selectors. (#1714)
- Fix potentially hung async selectors when shared across multiple roots that depend on atoms initialized with promises that don't resolve. (#1714)
Recoil 0.7
Recoil 0.7 offers some minor API improvements, selector optimizations, and other fixes.
New Features
Atom Defaults are Optional
It is now optional to provide a default value for an atom. If no default is provided the atom will be kept in a "pending" state (e.g. triggering React Suspense) until it is set. (#1639)
This can help avoid awkward typing (such as unecessarily making the type nullable) or awkward placeholder values for the default. An example minimal string atom might be:
atom<string>({key: 'MyString'});
This is also useful when atoms are initialized with atom effects and a default may not be necessary:
atom({
key: 'MyQuery',
effects: [
dbSyncEffect({query, variables}),
],
});
Other New Features
- Add
.getStoreID()
method toSnapshot
(#1612) - Publish
RecoilLoadable.loading()
factory for making an asyncLoadable
which never resolves. (#1641)
Improvements / Optimizations
Automatically retain snapshots for the duration of async callbacks.
You now no longer need to manually retain snapshots for async callbacks from useRecoilCallback()
. (#1632)
const myCallback = useRecoilCallback(({snapshot}) => async () => {
// No longer necessary to retain() here
await something;
... use snapshot ...
});
If you want to save a Snapshot or reference it from closure state from some other scheduled handler, then you still need to manually retain it.
Other Improvements / Optimizations
- Optimizations for scaling with more selector dependencies. 2x improvement with 100 dependencies, 4x with 1,000, and now able to support 10,000+ dependencies. (#1651, #1515, #914)
- Better error reporting when user selector implementations provide inconsistent results (#1696)
Breaking Changes
Selector evaluation or atom defaults can use a Loadable object
Now the selector get()
evaluation callback or atom default
property can use a Loadable
object. (#1640) This can allow them to more cleanly accept synchronous error states:
atom({
key: 'Key',
default: RecoilLoadable.error(new Error('ERROR')),
});
or mapped Loadables or placeholders:
selector({
key: 'Key',
get: ({get}) => {
const queryLoadable = get(noWait(myQuerySelector));
if (queryLoadable.state === 'loading') {
return PLACEHOLDER;
}
return queryLoadable; // Pass on the query results or error state.
}
})
If you wish to explicitly evaluate a selector value to a Promise
, Loadable
, or RecoilState
type object then you can now wrap them with selector.value()
or atom.value()
.
selector({
key: 'Key',
get: ({get}) => {
// Returns an immediate synchronous value
return selector.value(Promise.resolve('Promise as a value'));
},
});
This is only a minor change. It helps make the API more consisent for handling wrappers such as Promise
and Loadable
, though is not yet available across the entire API. But, it helps set the stage for future potential ability to explicitly set atoms and selectors to asynchronous values or error states.
Other Breaking Changes
useRecoilCallback()
now provides a snapshot for the latest state instead of the latest rendered state, which had bugs (#1610, #1604)
Fixes
Recoil 0.6
Recoil 0.6 introduces improved support for React 18, including concurrent rendering and transitions, along with new APIs, fixes, and optimizations.
Recoil 0.5
Welcome to Recoil 0.5 with a few new APIs and improvements.
Recoil 0.4.1
Recoil 0.4.1 has been released with some performance optimizations and fixes focused on optimizing when React will re-render components based on Recoil state changes.
Recoil 0.4
We are pleased to announce the release of Recoil 0.4 with configurable selector caches, improved API for transactions with multiple atoms, and other optimizations and fixes.
Recoil 0.3
We are pleased to announce the release of Recoil 0.3 with more flexible RecoilRoot nesting, callback generation, preparation for memory management, optimizations, and bug fixes.
Recoil 0.2
We are pleased to announce the release of Recoil 0.2.0. This release has a new, more reliable implementation of async selectors, greatly improved performance, and many bug fixes and improvements.
Recoil 0.1.1
Welcome to Recoil version 0.1.1! This release has performance improvements and introduces several experimental features such as support for React Native, working with Snapshots outside of React, and atom effects for managing side-effects of atoms such as logging, synchronization with external stores, persistence, etc.