{"record":{"id":"63aad8b5f95150f1","repo":"facebook/react","slug":"284","errorCode":"284","errorMessage":"Expected ref to be a function, an object returned by React.createRef(), or undefined/null.","messagePattern":"Expected ref to be a function, an object returned by React\\.createRef\\(\\), or undefined/null\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-reconciler/src/ReactFiberBeginWork.js","lineNumber":1422,"sourceCode":"    }\n  }\n  const nextProps: ProfilerProps = workInProgress.pendingProps;\n  const nextChildren = nextProps.children;\n  reconcileChildren(current, workInProgress, nextChildren, renderLanes);\n  return workInProgress.child;\n}\n\nfunction markRef(current: Fiber | null, workInProgress: Fiber) {\n  // TODO: Check props.ref instead of fiber.ref when enableRefAsProp is on.\n  const ref = workInProgress.ref;\n  if (ref === null) {\n    if (current !== null && current.ref !== null) {\n      // Schedule a Ref effect\n      workInProgress.flags |= Ref | RefStatic;\n    }\n  } else {\n    if (typeof ref !== 'function' && typeof ref !== 'object') {\n      throw new Error(\n        'Expected ref to be a function, an object returned by React.createRef(), or undefined/null.',\n      );\n    }\n    if (current === null || current.ref !== ref) {\n      // Schedule a Ref effect\n      workInProgress.flags |= Ref | RefStatic;\n    }\n  }\n}\n\nfunction mountIncompleteFunctionComponent(\n  _current: null | Fiber,\n  workInProgress: Fiber,\n  Component: any,\n  nextProps: any,\n  renderLanes: Lanes,\n) {\n  resetSuspendedCurrentOnMountInLegacyMode(_current, workInProgress);","sourceCodeStart":1404,"sourceCodeEnd":1440,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-reconciler/src/ReactFiberBeginWork.js#L1404-L1440","documentation":"markRef() validates every ref attached to a fiber before scheduling the Ref effect. React accepts exactly three ref shapes: a function (callback ref), a ref object (from useRef()/React.createRef()), or null/undefined. Any primitive - a string, number, boolean - throws during beginWork, before the element can render.","triggerScenarios":"Passing a legacy string ref (ref=\"input\"); passing a computed value that is a primitive (ref={someString}, ref={0}, ref={true}); spreading a props object that contains a stray ref key; forwarding a non-ref value through React.forwardRef.","commonSituations":"Codebases migrating off removed string-ref behavior; dynamically built props objects where a ref key leaks in from data; refactors where a callback ref loses its function wrapper; TypeScript code that bypasses ref types with any.","solutions":["Locate the offending element via the error's component stack and inspect its ref value","Replace string or primitive refs with an object ref (useRef/createRef) or a callback ref","If the ref arrives via a spread object, strip the ref key before spreading or set ref to a valid value","Type the prop as React.Ref<T> so the compiler rejects primitives"],"exampleFix":"// before\n<input ref=\"username\" />;\n\n// after\nfunction Form() {\n  const username = useRef(null);\n  return <input ref={username} />;\n}","handlingStrategy":"type-guard","validationCode":"function safeProps(props) {\n  if ('ref' in props && !isValidRef(props.ref)) {\n    throw new TypeError(`Invalid ref of type ${typeof props.ref}: ${String(props.ref)}`);\n  }\n  return props;\n}","typeGuard":"function isValidRef(ref) {\n  return (\n    ref == null ||\n    typeof ref === 'function' ||\n    (typeof ref === 'object' && 'current' in ref)\n  );\n}","tryCatchPattern":"Render-phase throw: an ErrorBoundary above the element catches it. Log the component stack, then fix the ref value at its source - retrying without the fix re-throws identically.","preventionTips":["Never use string refs - modern React does not support them","Type ref props as React.Ref<T>, never any","Strip stray ref keys from dynamically built props objects before spreading"],"tags":["refs","props","validation","beginwork"],"backgroundTag":"invalid-ref-type","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}