{"record":{"id":"680df29aad4da801","repo":"shadcn-ui/ui","slug":"component-must-be-used-within-a-questionnaire-c","errorCode":null,"errorMessage":"${component} must be used within a Questionnaire.Choice component.","messagePattern":"(.+?) must be used within a Questionnaire\\.Choice component\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/react/src/questionnaire/context.ts","lineNumber":32,"sourceCode":"  React.createContext<QuestionnaireItemContextValue | null>(null)\n\nfunction useQuestionnaireContext(component: string) {\n  const context = React.useContext(QuestionnaireContext)\n\n  if (!context) {\n    throw new Error(\n      `${component} must be used within a Questionnaire.Root component.`\n    )\n  }\n\n  return context\n}\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}","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/shadcn-ui/ui/blob/efac5987074af84ece57c367c6dd83387b967022/packages/react/src/questionnaire/context.ts#L14-L50","documentation":"useQuestionnaireChoiceContext() reads QuestionnaireChoiceContext and throws if a Choice-scoped part is rendered outside a <Questionnaire.Choice> ancestor. The guard enforces the compound-component hierarchy: choice-related subparts only make sense inside a Choice.","triggerScenarios":"Rendering Questionnaire.ChoiceLabel or another Choice-scoped part outside <Questionnaire.Choice>; restructuring JSX so the Choice wrapper is removed but its children remain.","commonSituations":"Composing custom Choice layouts and forgetting the Choice wrapper; testing a Choice subpart in isolation without a provider.","solutions":["Wrap the part in <Questionnaire.Choice>...","In tests, render the part inside a Choice (and its required ancestors).","Move the offending part under a Choice in the JSX."],"exampleFix":"// before\n<Questionnaire.ChoiceLabel /> // throws: no Choice ancestor\n\n// after\n<Questionnaire.Root>\n  <Questionnaire.Item>\n    <Questionnaire.Choice>\n      <Questionnaire.ChoiceLabel />\n    </Questionnaire.Choice>\n  </Questionnaire.Item>\n</Questionnaire.Root>","handlingStrategy":"validation","validationCode":"import * as React from \"react\"\nimport { QuestionnaireChoiceContext } from \"@/questionnaire/context\"\nconst ctx = React.useContext(QuestionnaireChoiceContext)\nif (!ctx) return null // render nothing instead of throwing","typeGuard":"import * as React from \"react\"\nimport { QuestionnaireChoiceContext } from \"@/questionnaire/context\"\nfunction useOptionalChoice() {\n  return React.useContext(QuestionnaireChoiceContext) // null when outside Choice\n}","tryCatchPattern":null,"preventionTips":["Always render Choice-scoped parts inside <Questionnaire.Choice>.","In tests, render parts inside the full ancestor chain (Root > Item > Choice).","Co-locate Choice 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"}