{"record":{"id":"cbddf2d9a6676cfe","repo":"facebook/react","slug":"231","errorCode":"231","errorMessage":"Expected `${registrationName}` listener to be a function, instead got a value of `${typeof listener}` type.","messagePattern":"Expected `(.+?)` listener to be a function, instead got a value of `(.+?)` type\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-native-renderer/src/ReactNativeGetListener.js","lineNumber":31,"sourceCode":"\nexport default function getListener(\n  inst: Fiber,\n  registrationName: string,\n): Function | null {\n  const stateNode = inst.stateNode;\n  if (stateNode === null) {\n    // Work in progress (ex: onload events in incremental mode).\n    return null;\n  }\n  const props = getFiberCurrentPropsFromNode(stateNode);\n  if (props === null) {\n    // Work in progress.\n    return null;\n  }\n  const listener = props[registrationName];\n\n  if (listener && typeof listener !== 'function') {\n    throw new Error(\n      `Expected \\`${registrationName}\\` listener to be a function, instead got a value of \\`${typeof listener}\\` type.`,\n    );\n  }\n\n  return listener;\n}\n","sourceCodeStart":13,"sourceCodeEnd":38,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-native-renderer/src/ReactNativeGetListener.js#L13-L38","documentation":"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.","triggerScenarios":"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.","commonSituations":"Boolean-conditional handlers written as onPress={condition}; passing state values or bound objects instead of callbacks; spreading untyped data into host components.","solutions":["Pass a function or omit the prop: onPress={enabled ? handlePress : undefined}.","When spreading props, forward on* keys only when the value is a function or nullish.","Type handler props with Flow/TS so non-functions fail at compile time."],"exampleFix":"// before\n<Pressable onPress={isEnabled} />\n\n// after\n<Pressable onPress={isEnabled ? handlePress : undefined} />","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"const isListener = value => value == null || typeof value === 'function';\n// usage\n<Pressable onPress={isListener(press) ? press : undefined} />;\n// when spreading:\nconst safeProps = Object.fromEntries(\n  Object.entries(props).filter(\n    ([key, value]) => !/^on/.test(key) || isListener(value),\n  ),\n);","tryCatchPattern":null,"preventionTips":["Write conditional handlers as cond ? handler : undefined, never cond ? handler : cond.","Never pass state values or objects to on* props of host components.","Type handler props (Flow/TS) so non-functions fail at compile time."],"tags":["react-native","event-handlers","props","type-error"],"backgroundTag":"invalid-event-handler-prop","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}