( unstableObject: Type )
| 2 | import { shallowCompare } from "../utils/shallowCompare"; |
| 3 | |
| 4 | export function useMemoizedObject<Type extends object>( |
| 5 | unstableObject: Type |
| 6 | ): Type { |
| 7 | const [memoizedObject, setMemoizedObject] = useState(unstableObject); |
| 8 | |
| 9 | if (!shallowCompare(memoizedObject, unstableObject)) { |
| 10 | setMemoizedObject(unstableObject); |
| 11 | |
| 12 | return unstableObject; |
| 13 | } |
| 14 | |
| 15 | return memoizedObject; |
| 16 | } |
no test coverage detected