import React , { useState , useEffect } from 'react' ; type Props = { asyncFetchTargets : any ; widgetId : number ; children : any ; } ; interface State { data : any [ ] ; fetching : boolean ; } const FetchTargets = ( { asyncFetchTargets , widgetId , children } ) => { const [ state , setState ] = useState < State > ( { data : [ ] , fetching : true } ) ; useEffect ( ( ) => { asyncFetchTargets ( { widget_id : widgetId } ) . then ( ( { data } ) => { setState ( { data : data ?. pressure_targets , fetching : false } ) ; } ) . catch ( ( err ) => { console . error ( 'FetchTargets: ' , err ) ; } ) ; } , [ ] ) ; if ( state . fetching ) return < div />; return children ( { data : state . data } ) ; } ; export default FetchTargets ;