|
Last change
on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
372 bytes
|
| Line | |
|---|
| 1 | import { useEffect, useRef } from './reactImports'
|
|---|
| 2 | import { shallowEqual } from './reactReduxImports'
|
|---|
| 3 |
|
|---|
| 4 | export function useShallowStableValue<T>(value: T) {
|
|---|
| 5 | const cache = useRef(value)
|
|---|
| 6 | useEffect(() => {
|
|---|
| 7 | if (!shallowEqual(cache.current, value)) {
|
|---|
| 8 | cache.current = value
|
|---|
| 9 | }
|
|---|
| 10 | }, [value])
|
|---|
| 11 |
|
|---|
| 12 | return shallowEqual(cache.current, value) ? cache.current : value
|
|---|
| 13 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.