MCPcopy
hub / github.com/buildbot/buildbot / useStateWithParentTrackingWithDefaultIfNotSet

Function useStateWithParentTrackingWithDefaultIfNotSet

www/ui/src/util/React.ts:29–42  ·  view source on GitHub ↗
(
    parentValue: T, defaultCallback: () => T)

Source from the content-addressed store, hash-verified

27// Just like useStateWithDefaultIfNotSet, however the current state is changed whenever a given
28// "parent" state is changed. The current state can otherwise be changed independently
29export function useStateWithParentTrackingWithDefaultIfNotSet<T>(
30 parentValue: T, defaultCallback: () => T): [T, (v: T) => void] {
31 const [lastParentValue, setLastParentValue] = useState(parentValue);
32 const [explicitValue, setExplicitValue] = useState<T | null>(null);
33
34 if (parentValue !== lastParentValue) {
35 setLastParentValue(parentValue);
36 setExplicitValue(parentValue);
37 return [parentValue, t => setExplicitValue(t)];
38 }
39
40 const value: T = explicitValue !== null ? explicitValue : defaultCallback();
41 return [value, t => setExplicitValue(t)];
42}
43
44function getWindowSize() {
45 return {

Callers 1

BuildSummary.tsxFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected