Stay up to date on releases
Create your free account today to subscribe to this repository for notifications about new releases, and build software alongside 40 million developers on GitHub.
Sign up for free See pricing for teams and enterprises
marvinhagemeister
released this
Happy belated New Years to everybody
New useErrorBoundary hook
There is a new hook called useErrorBoundary which allows you to catch errors that are thrown by any child components. It's essentially the hook version of componentDidCatch.
// 1. parameter is null or the error that was caught
// 2. paremeter can be called to reset the state
const [err, reset] = useErrorBoundary();
// Optional: You can pass a callback function that will
// be executed when an error occurs:
const [err] = useErrorBoundary(() => callMeMaybe());Usage example:
// Example component that will throw an error on render
const SomeComponent = () => {
throw new Error("fail");
};
const App = props => {
const [err] = useErrorBoundary();
if (err) {
return <p>Something went wrong...</p>;
} else {
return <SomeComponent />;
}
};Lazy works with non-default export
This PR was one of the smallest ones, but something that makes working with different kind of lazy loaded modules a lot easier. Previously lazy would always use the default export of the imported module. With this change it's now possible to use it with any export.
// Look ma, no default export
const LazyFoo = lazy(() => import("./Foo").then(m => m.MyComponent));On top of that we have the usual round of bug fixes. We'd like to thank everyone who reported them and helped us make Preact even better. Thank you so much!!
Features
- Add
useErrorBoundaryhook (#2205, thanks @JoviDeCroock) - Allow
lazy()usage with non-default imports (#2212, thanks @developit)
Bug Fixes
- Fix incorrect
refvalue on siblingvnodes(#2217, thanks @JoviDeCroock) - Fix stale closure in error boundary (#2225, thanks @JoviDeCroock)
- Fix
Textnodes being re-rendered unnecessarily (#2215, thanks @developit) - Shorten and correct
renderToStringdependency error (#2207, thanks @developit) - Support combination of
getDerivedStateFromErrorandcomponentDidCatch(#2200, thanks @JoviDeCroock) - Fix compat hydration (#2206, thanks @JoviDeCroock)
Typings
- Add
onReset/onFormDatato Form Event types (#2209, thanks @thesmartwon)
Maintenance
- More README updates (#2235, thanks @developit)
- Modernize our README (#2232, thanks @JoviDeCroock)
- Update package metadata (#2230, thanks @developit)
- Add more test cases for
Suspense(#2229, thanks @sventschui) - Fix renderer tests by using
sinonglobal (#2220, thanks @JoviDeCroock) - Update JSDoc comments (#2187, thanks @soulhat)