Submit
Path:
~
/
/
usr
/
share
/
grafana
/
public
/
app
/
plugins
/
datasource
/
influxdb
/
components
/
editor
/
query
/
influxql
/
hooks
/
File Content:
useShadowedState.ts
import { useState, useEffect } from 'react'; import { usePrevious } from 'react-use'; export function useShadowedState<T>(outsideVal: T): [T, (newVal: T) => void] { const [currentVal, setCurrentVal] = useState(outsideVal); const prevOutsideVal = usePrevious(outsideVal); useEffect(() => { const isOutsideValChanged = prevOutsideVal !== outsideVal; // if the value changes from the outside, we accept it into the state // (we only set it if it is different from the current value) if (isOutsideValChanged && currentVal !== outsideVal) { setCurrentVal(outsideVal); } }, [outsideVal, currentVal, prevOutsideVal]); return [currentVal, setCurrentVal]; }
Edit
Rename
Chmod
Delete
FILE
FOLDER
INFO
Name
Size
Permission
Action
useShadowedState.test.ts
2140 bytes
0644
useShadowedState.ts
688 bytes
0644
N4ST4R_ID | Naxtarrr