{"record":{"id":"939eebe73c772bf6","repo":"marmelab/react-admin","slug":"if-you-re-not-wrapping-the-checkboxgroupinput-insi-939eeb","errorCode":null,"errorMessage":"If you're not wrapping the CheckboxGroupInput inside a ReferenceArrayInput, you must provide the choices prop","messagePattern":"If you're not wrapping the CheckboxGroupInput inside a ReferenceArrayInput, you must provide the choices prop","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/input/CheckboxGroupInput.tsx","lineNumber":173,"sourceCode":"        source,\n        isFromReference,\n    } = useChoicesContext({\n        choices: choicesProp,\n        isFetching: isFetchingProp,\n        isLoading: isLoadingProp,\n        isPending: isPendingProp,\n        resource: resourceProp,\n        source: sourceProp,\n    });\n\n    if (source === undefined) {\n        throw new Error(\n            `If you're not wrapping the CheckboxGroupInput inside a ReferenceArrayInput, you must provide the source prop`\n        );\n    }\n\n    if (!isPending && !fetchError && allChoices === undefined) {\n        throw new Error(\n            `If you're not wrapping the CheckboxGroupInput inside a ReferenceArrayInput, you must provide the choices prop`\n        );\n    }\n\n    const {\n        field: { onChange: formOnChange, onBlur: formOnBlur, value, ref },\n        fieldState: { error, invalid },\n        id,\n        isRequired,\n    } = useInput({\n        format,\n        parse,\n        resource,\n        source,\n        validate,\n        onChange,\n        onBlur,\n        disabled,","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/input/CheckboxGroupInput.tsx#L155-L191","documentation":"CheckboxGroupInput requires a list of choices. When not pending and there is no fetch error, the merged choices (from props or the ReferenceArrayInput context) must still be defined; if undefined the component has nothing to render and throws rather than rendering an empty group silently.","triggerScenarios":"Standalone CheckboxGroupInput with source set but no choices prop and no data arriving from a ReferenceArrayInput; or ReferenceArrayInput returning undefined choices while isPending is false and no fetchError is set.","commonSituations":"Passing choices={undefined} due to a failed data fetch in custom code, forgetting the choices prop entirely, or a custom hook supplying an undefined choices value.","solutions":["Provide a choices array: <CheckboxGroupInput source=\"roles\" choices={[{id:'admin',name:'Admin'}]} />","Wrap in ReferenceArrayInput so choices come from the referenced resource","If choices are computed, default them to [] so the value is never undefined"],"exampleFix":"// before\nconst myChoices = fetchDataMaybe();\n<CheckboxGroupInput source=\"roles\" choices={myChoices} />\n// after\n<CheckboxGroupInput source=\"roles\" choices={myChoices ?? []} />","handlingStrategy":"validation","validationCode":"if (!isPending && !fetchError && !Array.isArray(allChoices)) {\n  throw new Error('CheckboxGroupInput requires a defined choices array');\n}","typeGuard":"const hasChoices = (\n  p: CheckboxGroupInputProps\n): p is CheckboxGroupInputProps & { choices: any[] } =>\n  Array.isArray(p.choices);","tryCatchPattern":"try {\n  render(<CheckboxGroupInput source=\"roles\" choices={maybeChoices} />);\n} catch (e) {\n  if (e.message.includes('must provide the choices prop')) {\n    render(<CheckboxGroupInput source=\"roles\" choices={[]} />);\n  }\n}","preventionTips":["Default dynamic choices to [] with nullish coalescing","When using ReferenceArrayInput, handle loading/error states rather than rendering the input conditionally with undefined data","Type choices as RaRecord[] and let TypeScript catch undefined assignments"],"tags":["react-admin","checkboxgroupinput","missing-prop"],"backgroundTag":"missing-required-prop","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}