import * as React from 'react'; import { createContext, ReactNode } from 'react'; import { RaRecord } from '../../types'; /** * Context to store a record. * * @see RecordContextProvider * @see useRecordContext */ export const RecordContext = createContext>( undefined ); RecordContext.displayName = 'RecordContext'; /** * Provider for the Record Context, to store a record. * * Use the useRecordContext() hook to read the context. * That's what the Edit and Show components do in mv-tmp. * * Many mv-tmp components read the RecordContext, including all Field * components. * * @example * * import { useGetOne, RecordContextProvider } from 'ra-core'; * * const Show = ({ resource, id }) => { * const { data } = useGetOne(resource, { id }); * return ( * * ... * * ); * }; */ export const RecordContextProvider = < RecordType extends RaRecord | Omit = RaRecord >({ children, value, }: RecordContextProviderProps) => ( {children} ); export interface RecordContextProviderProps { children: ReactNode; value?: RecordType; }