{"record":{"id":"cd73a24f3055e2c3","repo":"marmelab/react-admin","slug":"usecreatesuggestioncontext-must-be-used-inside-a-c","errorCode":null,"errorMessage":"useCreateSuggestionContext must be used inside a CreateSuggestionContext.Provider","messagePattern":"useCreateSuggestionContext must be used inside a CreateSuggestionContext\\.Provider","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/controller/input/useSupportCreateSuggestion.tsx","lineNumber":162,"sourceCode":"    handleChange: (eventOrValue: ChangeEvent | any) => Promise<void>;\n    createElement: ReactElement | null;\n    getOptionDisabled: (option: any) => boolean;\n}\n\nconst CreateSuggestionContext = createContext<\n    CreateSuggestionContextValue | undefined\n>(undefined);\n\ninterface CreateSuggestionContextValue {\n    filter?: string;\n    onCreate: (choice: any) => void;\n    onCancel: () => void;\n}\n\nexport const useCreateSuggestionContext = () => {\n    const context = useContext(CreateSuggestionContext);\n    if (!context) {\n        throw new Error(\n            'useCreateSuggestionContext must be used inside a CreateSuggestionContext.Provider'\n        );\n    }\n    return context;\n};\n\nexport type OnCreateHandler = (filter?: string) => any | Promise<any>;\n","sourceCodeStart":144,"sourceCodeEnd":170,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/controller/input/useSupportCreateSuggestion.tsx#L144-L170","documentation":"useCreateSuggestionContext is the hook that custom 'create' dialog components call to get { filter, onCreate, onCancel } from the CreateSuggestionContext. The context is only provided by react-admin's create-suggestion machinery while the create dialog is mounted. This error is thrown when the hook is called outside that provider, so there is no suggestion context to return.","triggerScenarios":"Calling useCreateSuggestionContext in a component rendered outside the create-suggestion provider: e.g. in a standalone page, outside an AutocompleteInput's `create` element, or in a component mounted somewhere else (like a regular form or modal not wired through the `create` prop).","commonSituations":"Reusing the same dialog component both inside an AutocompleteInput `create` prop and elsewhere; rendering the create dialog manually instead of via the `create` prop; missing CreateSuggestionContext.Provider after refactoring; copy-pasting a demo component into a wrong location.","solutions":["Ensure the component calling useCreateSuggestionContext is passed as the `create` prop of AutocompleteInput (or similar): create={<CreateTagDialog />}","Do not render the create dialog component manually or on its own route","If the component is used in multiple places, guard with a conditional call or split into a wrapper for the create case"],"exampleFix":"// before\n<CreateTagDialog /> // rendered outside the input, hook throws\n// after\n<AutocompleteInput source=\"tag\" create={<CreateTagDialog />} />","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"import { isValidElement } from 'react';\nconst isInsideCreateSuggestion = (child) => isValidElement(child) && child.type === CreateTagDialog; // ensure rendered via create={<.../>} prop","tryCatchPattern":null,"preventionTips":["Only call useCreateSuggestionContext inside a component used as the `create` prop","Never render the create dialog manually or share it as a general-purpose page","If reuse is needed, split hook usage into a wrapper component dedicated to the create case"],"tags":["react-admin","react-context","hooks","provider-missing"],"backgroundTag":"hook-used-outside-provider","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}