MCPcopy Create free account
hub / github.com/effector/effector / useEventBase

Function useEventBase

src/react/apiBase.ts:349–368  ·  view source on GitHub ↗
(eventObject: any, scope?: Scope)

Source from the content-addressed store, hash-verified

347}
348
349export function useEventBase(eventObject: any, scope?: Scope) {
350 useDeprecate(true, 'useEvent', 'useUnit')
351 if (!scope) {
352 return eventObject
353 }
354 const isShape = !is.unit(eventObject) && typeof eventObject === 'object'
355 const events = isShape ? eventObject : {event: eventObject}
356
357 return React.useMemo(() => {
358 if (is.unit(eventObject)) {
359 //@ts-expect-error
360 return scopeBind(eventObject, {scope})
361 }
362 const shape = Array.isArray(eventObject) ? [] : ({} as any)
363 for (const key in eventObject) {
364 shape[key] = scopeBind(eventObject[key], {scope})
365 }
366 return shape
367 }, [scope, ...Object.keys(events), ...Object.values(events)])
368}
369
370export function useGateBase<Props>(
371 GateComponent: Gate<Props>,

Callers 2

useEventFunction · 0.90
useEventFunction · 0.90

Calls 2

useDeprecateFunction · 0.90
scopeBindFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…