MCPcopy
hub / github.com/desktop/desktop / setState

Function setState

app/src/lib/set-state.ts:12–36  ·  view source on GitHub ↗
(
  component: T,
  stateKey: K
)

Source from the content-addressed store, hash-verified

10 * closures on each render.
11 */
12export function setState<T extends React.Component, K extends keyof T['state']>(
13 component: T,
14 stateKey: K
15) {
16 let setters = componentCache.get(component)
17
18 if (!setters) {
19 setters = new Map()
20 componentCache.set(component, setters)
21 }
22
23 const cachedSetter = setters.get(stateKey as string)
24
25 if (cachedSetter) {
26 return cachedSetter
27 }
28
29 const setter = (value: T['state'][K]) => {
30 component.setState({ [stateKey]: value })
31 }
32
33 setters.set(stateKey as string, setter)
34
35 return setter
36}

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected