{"record":{"id":"75762dd6644d0149","repo":"marmelab/react-admin","slug":"usesetinspectortitle-cannot-be-called-outside-of-a","errorCode":null,"errorMessage":"useSetInspectorTitle cannot be called outside of a PreferencesEditorContext","messagePattern":"useSetInspectorTitle cannot be called outside of a PreferencesEditorContext","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/preferences/useSetInspectorTitle.ts","lineNumber":13,"sourceCode":"import { useEffect } from 'react';\nimport { usePreferencesEditor } from './usePreferencesEditor';\n\n/**\n * Set inspector title on mount\n *\n * @example\n * useSetInspectorTitle('Datagrid');\n */\nexport const useSetInspectorTitle = (title: string, options?: any) => {\n    const preferencesEditorContext = usePreferencesEditor();\n    if (!preferencesEditorContext) {\n        throw new Error(\n            'useSetInspectorTitle cannot be called outside of a PreferencesEditorContext'\n        );\n    }\n    const { setTitle } = preferencesEditorContext;\n\n    useEffect(() => {\n        setTitle(title, options);\n        // eslint-disable-next-line react-hooks/exhaustive-deps\n    }, [title, JSON.stringify(options), setTitle]);\n};\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/preferences/useSetInspectorTitle.ts#L1-L24","documentation":"useSetInspectorTitle sets the title of the preferences inspector panel; it relies on the PreferencesEditorContext via usePreferencesEditor. Even though the message suggests a separate 'PreferencesEditorContext', the actual guard fires when usePreferencesEditor returned no context, i.e. the hook is called outside the preferences editor setup.","triggerScenarios":"Calling useSetInspectorTitle('Datagrid') from a component not rendered inside the preferences editor context — e.g. a custom DataGrid configuration component used outside <Configurable>'s editor, or when the Admin has no preferences editor enabled.","commonSituations":"Writing a custom DatagridConfig editor component but importing/placing it in the rendered page instead of the Configurable editor slot; using the hook in an app with a custom Admin without inspector support; tests without the provider.","solutions":["Only call useSetInspectorTitle from components rendered inside the preferences editor (the editor prop of <Configurable>).","Enable the preferences editor in <Admin> (supported build/configuration) so the context exists.","In tests, wrap the component with PreferencesEditorContext.Provider supplying a setTitle function."],"exampleFix":"// before (used in page component)\nconst Datagrid = () => {\n    useSetInspectorTitle('Datagrid'); // throws\n    return <RaDatagrid {...props} />;\n};\n\n// after (used in the editor component)\nconst DatagridEditor = () => {\n    useSetInspectorTitle('Datagrid');\n    return <PreferencesEditor />;\n};\n<Configurable editor={<DatagridEditor />}>\n    <Datagrid />\n</Configurable>;","handlingStrategy":"validation","validationCode":"import { useContext } from 'react';\nimport { PreferencesEditorContext } from 'ra-core';\nconst ctx = useContext(PreferencesEditorContext);\nif (ctx) {\n    useSetInspectorTitle('Datagrid');\n}","typeGuard":"const hasPreferencesEditor = (v: PreferencesEditorContextValue | null): v is PreferencesEditorContextValue => v != null;","tryCatchPattern":null,"preventionTips":["Call useSetInspectorTitle only from Configurable editor components.","Never call it from page-level rendered components.","In tests, stub the context with a setTitle spy."],"tags":["react","context","preferences","hooks"],"backgroundTag":"react-hook-outside-provider","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}