import { ReactNode , ReactElement } from 'react' ; import get from 'lodash/get' ; import { Record } from '../../types' ; import getResourceLinkPath , { LinkToFunctionType } from './getResourceLinkPath' ; import useReference , { UseReferenceProps } from '../useReference' ; interface ChildrenParams extends UseReferenceProps { resourceLinkPath : string | false ; } export interface ReferenceFieldControllerProps { basePath : string ; children : ( params : ChildrenParams ) => ReactNode ; record ? : Record ; reference : string ; resource : string ; source : string ; link ? : string | boolean | LinkToFunctionType ; label ? : string ; } example example example export const ReferenceFieldController = ( props ) => { const { children , record , source , ... rest } = props ; const id = get ( record , source ) ; return children ( { ... useReference ( { ... rest , id } ) , resourceLinkPath : getResourceLinkPath ( { ... rest , record , source } ) , } ) as ReactElement < any > ; } ; export default ReferenceFieldController ;