react-code-dataset
/
react-instantsearch
/packages
/react-instantsearch-hooks
/src
/lib
/useStableValue.ts
| import { useState } from 'react'; | |
| import { dequal } from '../lib/dequal'; | |
| export function useStableValue<TValue>(value: TValue) { | |
| const [stableValue, setStableValue] = useState<TValue>(() => value); | |
| if (!dequal(stableValue, value)) { | |
| setStableValue(value); | |
| } | |
| return stableValue; | |
| } | |