useComponentWillReceiveUpdate
now returns whether the props have changed. You can early return your component to skip the JSX creation, so React can re-execute the component function earlier.
Core Changes
- Add
createLocalStorageState
andcreateSessionStorageState
. Example usage:
// src/context/sidebar-active.tsx
import { createLocalStorageState } from 'foxact/create-local-storage-state';
const [useSidebarActive, useSidebarActiveValue] = createLocalStorageState(
'sidebar-active', // The localStorage key
/**
* The initial value to use if there is no item in the local storage with the provided key,
* the undefined value will be used if no initial value is provided.
*
* Also, the initial value will also be used during the server-side rendering, see below.
*/
false,
/**
* Optional configuration object enables the customization of value serialization before it's stored in local storage.
*/
{
// Optional, default to false. When set to "true", the value will be passed to the localStorage API as is.
raw: false,
// Optional, default to "JSON.stringify". Can only be specified when the "raw" is set to false (which is the default).
serializer: JSON.stringify,
// Optional, default to "JSON.parse". Can only be specified when the "raw" is set to false (which is the default).
deserializer: JSON.parse,
}
);
export { useSidebarActive, useSidebarActiveValue };
And now you can use the getter and setter hooks anywhere in your app:
// src/components/sidebar.tsx
import { memo } from 'react';
import { useSidebarActive, useSidebarActiveValue } from '../context/sidebar-active';
function Sidebar() {
const [sidebarActive, setSidebarActive] = useSidebarActive();
// If you only need the value, you can use `useSidebarActiveValue` instead:
const sidebarActive = useSidebarActiveValue();
return (
<div className={`sidebar ${sidebarActive ? 'active' : ''}`}>
<button onClick={() => setSidebarActive(false)}>Close Sidebar</button>
</div>
);
}
export default memo(Sidebar);
See the documentation for more information.
Core Changes
- Add
useComponentWillReceiveUpdate
which mimics the behavior ofUNSAFE_componentWillReceiveProps
.
Core Changes
- Add
useIsOnline
,usePageVisibility
anduseTypeScriptHappyCallback
Core Changes
foxact/rem
now also exports converter factory functionfoxact/rem
now supports customize html font size
Core Changes
- Add
foxact/types
createFixedArray
now supports GC-friendly array creation whenWeakRef
is available- Created array will be garbage-collected if not used (e.g. all components that use the array are unmounted)
Misc Changes
- Improve the types of
useLocalStorage
anduseSessionStorage
.
Core Changes
-
Add
useMediaQuery
-
useCompositionInput
now supports<textarea />
export const Example2 = () => { const textareaProps = useCompositionInput<HTMLTextAreaElement>(useCallback((value: string) => { // Do something with the value }, [])); return ( <textarea {...textareaProps} // useCompositionInput is uncontrolled, so you might need to provide defaultValue defaultValue={defaultValue} /> ); }
Core Changes
- Add
useAbortableEffect
Core Changes
- Make
no-ssr
digest configurable - Change default digest of
no-ssr
to the Next.js latest digest
Core Changes
- Add
unstable_useNextLink
Breaking Changes
<CurrentYear />
component change from default export to named export
Core Changes
rem
andem
functions now accepts multiple valuesinvariant
function now accepts custom error message- Add
<CurrentYear />
component
Misc Changes
- Improve error messages
Core Changes
- Add
invariant
function - Add
nullthrow
function - Re-implement
unstable_useUrlHashState
Core Changes
- Add
useSessionStorage
- Improve performance of
noSSR
Core Changes
- Allow the
deserializer
ofuseLocalStorage
to return an un-memoized value
Core Changes
- Allow customize
useLocalStorage
'sserializer
anddeserializer
Core Changes
- Make
noSSR
only throw on the server
Core Changes
- Add
unstable_useUrlHashState
- Add
useLocalStorage
- Add
noSSR
Core Changes
- Remove leaking
dependencies
Core Changes
- Add
rem
andem
CSS units converter - Disallow
useDebouncedValue
a function
Core Changes
- Add
composeContextProvider
Core Changes
- Change
createFixedArray
's return types
Core Changes
- Add
forceSetValue
touseDebouncedState
- Add
createFixedArray
Core Changes
- Fix
useNextPathname
to work with Next.js - Add
useSingleton
Misc Changes
- Refactor
useCompositionInput
to useuseSingleton
- Refactor
useUncontrolled
, remove the memoization of the inline reducer
Core Changes
- Add
useNextPathname
Core Changes
- Add
useIsClient
- Make
useErrorBoundary
's parameter optional
Core Changes
- Make the 2nd parameter of
useReactRouterIsMatch
optional - Add invariant type check for
NavigationContext
inuseReactRouterEnableConcurrentNavigation
Core Changes
- Add
useReactRouterEnableConcurrentNavigation
and<ReactRouterConcurrentNavigationProvider />
Core Changes
- Add
useReactRouterIsMatch
Misc Changes
-
Replace
eslint-plugin-import
witheslint-plugin-i
-
Why you should also do
npm install -D eslint-plugin-import@npm:eslint-plugin-i@latest
in your projects:
-
Misc Changes
- Making
useUncontrolled
more React Concurrent Rendering resilient by avoiding a hacky workaround.
Core Changes
- Add
useCompositionInput
createContextState
now returns a fourth value in the tuple, which is the React Context that holds the state value. It is designed to be used withReact.use
.
Core Changes
- Add
useDebouncedValue
anduseDebouncedValue
Core Changes
- Add
onCopyError
touseClipboard
- Introduce
useStableHandler
Misc Changes
- Documentation: https://foxact.skk.moe
- Finish TSDocs
Misc Changes
- Publish
sizes.json
Misc Changes
- Add CI to auto publish release
- Enable npm provenance
Core Changes
useArray
now supports remove by index.
Core Changes
useMap
, useSet
, useArray
now accept an optional initial value.
Core Changes
- New hook:
useMap
- New hook:
useSet
- New hook:
useArray
- New hook:
useErrorBoundary
- New hook:
useUncontrolled
- New hook:
useClipboard
- New util:
noop
- New util:
request-idle-callback
- New util:
typescriptHappyForwardRef
Core Changes
- New hook:
useIsomorphicLayoutEffect
- New hook:
useIntersection
Misc Changes
- Enable minify for dist build
Initial release.