{"record":{"id":"2ff5d60a923d3700","repo":"shadcn-ui/ui","slug":"component-must-be-used-within-a-questionnaire-i","errorCode":null,"errorMessage":"${component} must be used within a Questionnaire.Item component.","messagePattern":"(.+?) must be used within a Questionnaire\\.Item component\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/react/src/questionnaire/context.ts","lineNumber":44,"sourceCode":"}\n\nfunction useQuestionnaireChoiceContext(component: string) {\n  const context = React.useContext(QuestionnaireChoiceContext)\n\n  if (!context) {\n    throw new Error(\n      `${component} must be used within a Questionnaire.Choice component.`\n    )\n  }\n\n  return context\n}\n\nfunction useQuestionnaireItemContext(component: string) {\n  const context = React.useContext(QuestionnaireItemContext)\n\n  if (!context) {\n    throw new Error(\n      `${component} must be used within a Questionnaire.Item component.`\n    )\n  }\n\n  return context\n}\n\nexport {\n  QuestionnaireChoiceContext,\n  QuestionnaireContext,\n  QuestionnaireItemContext,\n  useQuestionnaireChoiceContext,\n  useQuestionnaireContext,\n  useQuestionnaireItemContext,\n}\n","sourceCodeStart":26,"sourceCodeEnd":60,"githubUrl":"https://github.com/shadcn-ui/ui/blob/efac5987074af84ece57c367c6dd83387b967022/packages/react/src/questionnaire/context.ts#L26-L60","documentation":"useQuestionnaireItemContext() reads QuestionnaireItemContext and throws if an Item-scoped part is rendered outside a <Questionnaire.Item> ancestor. The guard enforces that item-related subparts are only used within an Item.","triggerScenarios":"Rendering an Item-scoped Questionnaire part outside <Questionnaire.Item>; restructuring JSX so the Item wrapper is removed but its children remain.","commonSituations":"Building custom item layouts and forgetting the Item wrapper; testing an Item subpart in isolation without a provider.","solutions":["Wrap the part in <Questionnaire.Item>...","In tests, render the part inside an Item (and its required ancestors).","Move the offending part under an Item in the JSX."],"exampleFix":"// before\n<Questionnaire.ItemTitle /> // throws: no Item ancestor\n\n// after\n<Questionnaire.Root>\n  <Questionnaire.Item>\n    <Questionnaire.ItemTitle />\n  </Questionnaire.Item>\n</Questionnaire.Root>","handlingStrategy":"validation","validationCode":"import * as React from \"react\"\nimport { QuestionnaireItemContext } from \"@/questionnaire/context\"\nconst ctx = React.useContext(QuestionnaireItemContext)\nif (!ctx) return null // render nothing instead of throwing","typeGuard":"import * as React from \"react\"\nimport { QuestionnaireItemContext } from \"@/questionnaire/context\"\nfunction useOptionalItem() {\n  return React.useContext(QuestionnaireItemContext) // null when outside Item\n}","tryCatchPattern":null,"preventionTips":["Always render Item-scoped parts inside <Questionnaire.Item>.","In tests, render parts inside the full ancestor chain (Root > Item).","Co-locate Item subparts so they are not imported bare."],"tags":["react","context","questionnaire","provider"],"backgroundTag":null,"analyzedSha":"efac5987074af84ece57c367c6dd83387b967022","analyzedAt":"2026-08-12T05:00:50.218Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}