import maxBy from 'lodash/maxBy' ; import React , { useMemo } from 'react' ; import { UnknownRenderer } from './UnknownRenderer' ; import { DispatchCellProps } from '@jsonforms/core' ; import { withJsonFormsDispatchCellProps } from './JsonFormsContext' ; /**
 * Dispatch renderer component for cells.
 */ export const Dispatch = ( { uischema , schema , path , cells , id , enabled , renderers } ) => { const cell = useMemo ( ( ) => maxBy ( cells , r => r . tester ( uischema , schema ) ) , [ cells , uischema , schema ] ) ; if ( cell === undefined || cell . tester ( uischema , schema ) === - 1 ) { return < UnknownRenderer type = { 'cell' } />; } else { const Cell = cell . cell ; return ( < Cell uischema = { uischema } schema = { schema } enabled = { enabled } path = { path } id = { id } renderers = { renderers } cells = { cells } / > ) ; } } ; export const DispatchCell = withJsonFormsDispatchCellProps ( Dispatch ) ;