{"record":{"id":"c99853521672eada","repo":"marmelab/react-admin","slug":"usegetrecordid-could-not-find-the-current-record-i","errorCode":null,"errorMessage":"useGetRecordId could not find the current record id. You need to use it inside a RecordContextProvider, or inside a supported route, or provide the record id to the hook yourself.","messagePattern":"useGetRecordId could not find the current record id\\. You need to use it inside a RecordContextProvider, or inside a supported route, or provide the record id to the hook yourself\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/dataProvider/useGetRecordId.ts","lineNumber":22,"sourceCode":"\n/**\n * Helper hook to get the current `recordId`.\n *\n * `recordId` is obtained from parameters if passed as a parameter, or from the `RecordContext` if there is one, or, lastly, from the router URL.\n *\n * @param {any} recordId optional if used inside a RecordContextProvider or if recordId can be guessed from the URL\n *\n * @returns The `recordId` determined in this manner.\n *\n * @example\n * const recordId = useGetRecordId();\n */\nexport function useGetRecordId(recordId?: Identifier): Identifier {\n    const contextRecord = useRecordContext<RaRecord>();\n    const { id: routeId } = useParams<{ id?: string }>();\n    const actualRecordId = recordId ?? contextRecord?.id ?? routeId;\n    if (actualRecordId == null)\n        throw new Error(\n            `useGetRecordId could not find the current record id. You need to use it inside a RecordContextProvider, or inside a supported route, or provide the record id to the hook yourself.`\n        );\n\n    return actualRecordId;\n}\n","sourceCodeStart":4,"sourceCodeEnd":28,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/dataProvider/useGetRecordId.ts#L4-L28","documentation":"useGetRecordId resolves the current record id from, in order: the explicit recordId argument, the RecordContext, or the :id route param. If all three are absent there is no way to determine the id, so the hook throws with guidance on the three supported sources.","triggerScenarios":"Calling useGetRecordId() in a component rendered outside any RecordContextProvider; using it on a route without an :id segment (e.g. list or create pages); passing an explicit undefined recordId while no record is in context.","commonSituations":"Custom edit-page widgets moved to a list page; components rendered in a portal or modal outside the RecordContext; forgetting to pass record prop so RecordContext is empty; routing changes that renamed the :id param.","solutions":["Wrap the component in <RecordContextProvider value={record}>.","Pass the id explicitly: useGetRecordId(record.id).","Render the component only on routes with an :id path param (edit/show routes)."],"exampleFix":"// before\nconst id = useGetRecordId(); // throws: no context, no route id\n// after\nconst id = useGetRecordId(record?.id);","handlingStrategy":"type-guard","validationCode":"const record = useRecordContext();\nconst { id: routeId } = useParams<{ id?: string }>();\nif (record?.id == null && routeId == null) return <MissingIdFallback />;","typeGuard":"const canResolveId = (r?: { id?: unknown }, routeId?: string): boolean =>\n  r?.id != null || routeId != null;","tryCatchPattern":"// hooks cannot be wrapped in try/catch; gate the component instead\nif (!canResolveId(record, routeId)) return null;","preventionTips":["Only call useGetRecordId inside RecordContextProvider or :id routes.","Pass recordId explicitly when the component is reused outside edit/show pages.","Keep route param named :id or supply the id manually."],"tags":["react-admin","hooks","record-context","routing"],"backgroundTag":"missing-context-provider","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}