Gathering detailed insights and metrics for @shopify/react-hooks
Gathering detailed insights and metrics for @shopify/react-hooks
Gathering detailed insights and metrics for @shopify/react-hooks
Gathering detailed insights and metrics for @shopify/react-hooks
@shopify/hydrogen-react
React components, hooks, and utilities for creating custom Shopify storefronts
@shopify/react-form
Manage React forms tersely and safely-typed with no magic using React hooks
@shopwp/hooks
React hooks library for ShopWP.
react-shopify-hooks
Collection of React hooks for interacting with the Shopify API
[⚠️ Deprecated] A loosely related set of packages for JavaScript/TypeScript projects at Shopify
npm install @shopify/react-hooks
Typescript
Module System
Min. Node Version
Node Version
NPM Version
@shopify/react-i18n-universal-provider@3.1.8
Updated on Jan 10, 2025
@shopify/react-i18n@7.14.0
Updated on Jan 10, 2025
@shopify/name@1.3.0
Updated on Jan 10, 2025
@shopify/dates@2.1.1
Updated on Jan 10, 2025
@shopify/react-i18n-universal-provider@3.1.7
Updated on Jan 10, 2025
@shopify/react-i18n@7.13.2
Updated on Jan 10, 2025
TypeScript (96.39%)
Ruby (2.34%)
JavaScript (1.23%)
Shell (0.02%)
CSS (0.02%)
Total Downloads
29,398,978
Last Day
2,674
Last Week
41,339
Last Month
189,018
Last Year
5,746,119
MIT License
1,692 Stars
4,974 Commits
226 Forks
386 Watchers
249 Branches
7,214 Contributors
Updated on Jun 04, 2025
Minified
Minified + Gzipped
Latest Version
4.1.2
Package Id
@shopify/react-hooks@4.1.2
Unpacked Size
37.21 kB
Size
9.93 kB
File Count
72
NPM Version
10.7.0
Node Version
18.20.4
Published on
Aug 01, 2024
Cumulative downloads
Total Downloads
Last Day
8.3%
2,674
Compared to previous day
Last Week
-10.3%
41,339
Compared to previous week
Last Month
-24.4%
189,018
Compared to previous month
Last Year
-16.6%
5,746,119
Compared to previous year
1
2
@shopify/react-hooks
A collection of primitive React hooks.
1yarn add @shopify/react-hooks
useDebouncedValue()
This hook provides a debounced value.
1function MyComponent() {
2 const [searchValue, setSearchValue] = useState('');
3 const debouncedSearch = useDebouncedValue(searchValue);
4 const {data, loading} = useQuery(SomeQuery, {
5 variables: {
6 query: debouncedSearch,
7 },
8 });
9
10 function handleSearchTextChange(evt: React.KeyboardEvent) {
11 setSearchValue(evt.currentTarget.value);
12 }
13
14 return <input onChange={handleSearchTextChange} />;
15}
useDelayedCallback()
This hook provides a delayed callback function. It takes a callback and a delay in milliseconds. This might be useful when you want to invoke a callback after a certain delay.
1function MyComponent() { 2 const delay = 300; 3 const callback = () => { 4 console.log( 5 `Oh, you KNOW I'm calling that callback after ${delay} milliseconds!`, 6 ); 7 }; 8 9 const callbackWithDelay = useDelayedCallback(callback, delay); 10 11 const onClick = () => { 12 callbackWithDelay(); 13 }; 14 15 return <button onClick={onClick}>Click me!</button>; 16}
useForceUpdate()
This hook provides a forceUpdate
function which will force a component to re-render. This might be useful when you want to re-render after a mutable object gets updated.
1const mutableObject = {foo: 'bar'}; 2export default function ResourceListFiltersExample() { 3 const forceUpdate = useForceUpdate(); 4 const onClick = () => { 5 mutableObject.foo = 'bar' + new Date().getTime(); 6 forceUpdate(); 7 }; 8 9 return <button onClick={onClick}>Click Me</button>; 10}
useOnValueChange()
This hook tracks a given value and invokes a callback when it has changed.
1function MyComponent({foo}: {foo: string}) { 2 useOnValueChange(foo, (newValue, oldValue) => { 3 console.log(`foo changed from ${oldValue} to ${newValue}`); 4 }); 5 6 return null; 7}
useTimeout()
This hook provides a declarative version of setTimeout()
. The first argument is a callback that will be invoked after the given delay (number of milliseconds) as the second argument. Optionally, the timeout can be disabled by passing null
as the delay.
1function MyComponent() { 2 const [status, setStatus] = React.useState('Pending'); 3 const pending = status === 'Pending'; 4 5 const buttonLabel = pending ? 'Cancel' : 'Reset'; 6 const handleClick = () => setStatus(pending ? 'Cancelled' : 'Pending'); 7 const delay = pending ? 1000 : null; 8 9 useTimeout(() => setStatus('Fired'), delay); 10 11 return ( 12 <div> 13 <div>{status}</div> 14 <button onClick={handleClick}>{buttonLabel}</button> 15 </div> 16 ); 17}
useInterval()
This hook provides a declarative version of setInterval
. The first argument is a callback that will be invoked successively after the given delay (number of milliseconds) as the second argument. Optionally, the interval can be disabled by passing null
as the delay.
1function MyComponent() { 2 const [counter, setCounter] = React.useState(0); 3 const [enabled, setEnabled] = React.useState(true); 4 5 const delay = enabled ? 1000 : null; 6 const label = enabled ? 'Disable' : 'Enable'; 7 const toggle = () => setEnabled(!enabled); 8 9 useInterval(() => setCounter(counter + 1), delay); 10 11 return ( 12 <div> 13 <div>{counter}</div> 14 <button onClick={toggle}>{label}</button> 15 </div> 16 ); 17}
This is a TypeScript implementation of @gaeron's useInterval
hook from the Overreacted blog post.
useIsomorphicLayoutEffect()
This hook is a drop-in replacement for useLayoutEffect
that can be used safely in a server-side rendered app. It resolves to useEffect
on the server and useLayoutEffect
on the client (since useLayoutEffect
cannot be used in a server-side environment).
Refer to the useLayoutEffect
documentation to learn more.
useLazyRef()
This hook creates a ref object like React’s useRef
, but instead of providing it the value directly, you provide a function that returns the value. The first time the hook is run, it will call the function and use the returned value as the initial ref.current
value. Afterwards, the function is never invoked. You can use this for creating refs to values that are expensive to initialize.
1function MyComponent() { 2 const ref = useLazyRef(() => someExpensiveOperation()); 3 4 React.useEffect(() => { 5 console.log('Initialized expensive ref', ref.current); 6 }); 7 8 return null; 9}
useMedia()
& useMediaLayout()
This hook listens to a MediaQueryList created via matchMedia and returns true or false if it matches the media query string.
useMediaLayout
is similar to useMedia
but it uses useLayoutEffect
internally to re-render synchronously.
1function MyComponent() { 2 const isSmallScreen = useMedia('(max-width: 640px)'); 3 return ( 4 <p> 5 {isSmallScreen ? 'This is a small screen' : 'This is not a small screen'} 6 </p> 7 ); 8}
useMountedRef()
This hook keeps track of a component's mounted / un-mounted status and returns a ref object like React’s useRef
with a boolean value representing said status. This is often used when a component contains an async task that sets state after the task has resolved.
1import React from 'react'; 2import {useMountedRef} from '@shopify/react-hooks'; 3 4function MockComponent() { 5 const [result, setResult] = React.useState(); 6 const mounted = useMountedRef(); 7 8 async function handleOnClick() { 9 const result = await fetchData(); 10 11 if (mounted.current) { 12 setData(result); 13 } 14 } 15 16 return ( 17 <button onClick={handleOnClick} type="button"> 18 Fetch Data 19 </button> 20 ); 21}
usePrevious()
This hook stores the previous value of a given variable.
1function Score({value}) { 2 const previousValue = usePrevious(value); 3 const newRecord = value > previousValue ? <p>We have a new record!</p> : null; 4 5 return ( 6 <> 7 <p>Current score: {value}</p> 8 {newRecord} 9 </> 10 ); 11}
useToggle()
This hook provides an object that contains a boolean state value and a set of memoised callbacks to toggle it, force it to true, and force it to false. It accepts one argument that is the initial value of the state or an initializer function returning the initial value. This is useful for toggling the active state of modals and popovers.
1function MyComponent() { 2 const { 3 value: isActive, 4 toggle: toggleIsActive, 5 setTrue: setIsActiveTrue, 6 setFalse: setIsActiveFalse, 7 } = useToggle(false); 8 const activeText = isActive ? 'true' : 'false'; 9 10 return ( 11 <> 12 <p>Value: {activeText}</p> 13 <button onClick={toggleIsActive}>Toggle isActive state</button> 14 <button onClick={setIsActiveTrue}>Set isActive state to true</button> 15 <button onClick={setIsActiveFalse}>Set isActive state to false</button> 16 </> 17 ); 18}
No vulnerabilities found.
Reason
all changesets reviewed
Reason
30 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
8 existing vulnerabilities detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-07-01
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More