import { useEffect , useState } from 'react' ; import { Task } from 'ProjectPlanner/types' ; import { api } from 'ProjectPlanner/api' ; export function useTask ( taskId ) { const [ task , setTask ] = useState < Task | null > ( null ) ; useEffect ( ( ) => { let isCurrent = true ; api . boards . getTask ( taskId ) . then ( ( task ) => { if ( isCurrent ) { setTask ( task ) ; } } ) ; return ( ) => { isCurrent = false ; } ; } , [ taskId ] ) ; return [ task , setTask ] as const ; }