import * as React from 'react' ; import { useState , useEffect } from 'react' ; import inflection from 'inflection' ; import { useListController , getElementsFromRecords , InferredElement , ListContextProvider , useResourceContext , } from 'ra-core' ; import ListView , { ListViewProps } from './ListView' ; import listFieldTypes from './listFieldTypes' ; import { ListProps } from '../types' ; example const ListGuesser = ( props ) => { const controllerProps = useListController ( props ) ; return ( < ListContextProvider value = { controllerProps } > < ListViewGuesser { ... props } { ... controllerProps } /> < /ListContextProvider>); } ; const ListViewGuesser = ( props ) => { const { ids , data } = props ; const resource = useResourceContext ( props ) ; const [ inferredChild , setInferredChild ] = useState ( null ) ; useEffect ( ( ) => { if ( ids . length > 0 && data && ! inferredChild ) { const inferredElements = getElementsFromRecords ( ids . map ( id => data [ id ] ) , listFieldTypes ) ; const inferredChild = new InferredElement ( listFieldTypes . table , null , inferredElements ) ; process . env . NODE_ENV !== 'production' && console . log ( `Guessed List:

export const ${ inflection . capitalize ( inflection . singularize ( resource ) ) }List = props => (
    <List {...props}>
${ inferredChild . getRepresentation ( ) }
    </List>
);` ) ; setInferredChild ( inferredChild . getElement ( ) ) ; } } , [ data , ids , inferredChild , resource ] ) ; return < ListView { ... props } > { inferredChild } < /ListView>; } ; ListViewGuesser . propTypes = ListView . propTypes ; export default ListGuesser ;