import * as React from 'react'; import { ReactElement } from 'react'; import { RaRecord } from '../../types'; import { RecordContextProvider } from './RecordContext'; /** * Wrap children with a RecordContext provider only if the value is defined. * * Allows a component to work outside of a record context. * * @example * * import { OptionalRecordContextProvider, TextField } from 'mv-tmp'; * * const RecordTitle = ({ record }) => ( * * * * ); */ export const OptionalRecordContextProvider = < RecordType extends RaRecord | Omit = RaRecord >({ value, children, }: { children: ReactElement; value?: RecordType; }) => value ? ( {children} ) : ( children );