facebook/react · error · Error

231

231

Error message

Expected `${registrationName}` listener to be a function, instead got a value of `${typeof listener}` type.

What it means

RN's event system reads listener props off host instances via getListener; if the prop registered for an event name is truthy but not a function (string, number, boolean, object), it throws at event resolution time - effectively a per-handler type check. null/undefined listeners are fine; only truthy non-functions fail.

Source

Thrown at packages/react-native-renderer/src/ReactNativeGetListener.js:31

export default function getListener(
  inst: Fiber,
  registrationName: string,
): Function | null {
  const stateNode = inst.stateNode;
  if (stateNode === null) {
    // Work in progress (ex: onload events in incremental mode).
    return null;
  }
  const props = getFiberCurrentPropsFromNode(stateNode);
  if (props === null) {
    // Work in progress.
    return null;
  }
  const listener = props[registrationName];

  if (listener && typeof listener !== 'function') {
    throw new Error(
      `Expected \`${registrationName}\` listener to be a function, instead got a value of \`${typeof listener}\` type.`,
    );
  }

  return listener;
}

View on GitHub (pinned to eafeac097b)

Solutions

  1. Pass a function or omit the prop: onPress={enabled ? handlePress : undefined}.
  2. When spreading props, forward on* keys only when the value is a function or nullish.
  3. Type handler props with Flow/TS so non-functions fail at compile time.

Example fix

// before
<Pressable onPress={isEnabled} />

// after
<Pressable onPress={isEnabled ? handlePress : undefined} />
Defensive patterns

Strategy: type-guard

Type guard

const isListener = value => value == null || typeof value === 'function';
// usage
<Pressable onPress={isListener(press) ? press : undefined} />;
// when spreading:
const safeProps = Object.fromEntries(
  Object.entries(props).filter(
    ([key, value]) => !/^on/.test(key) || isListener(value),
  ),
);

Prevention

When it happens

Trigger: Passing a truthy non-function to a registered handler prop on an RN host component: onPress={isEnabled}, onChange={settings.value}, or spreading a props object whose on* keys hold non-function values.

Common situations: Boolean-conditional handlers written as onPress={condition}; passing state values or bound objects instead of callbacks; spreading untyped data into host components.

Related errors


AI-assisted analysis of facebook/react@eafeac097b (2026-08-21). Data as JSON: /api/errors/cbddf2d9a6676cfe. Report an issue: GitHub.