import useFetch from "hooks/useFetch" ; import { useState , useEffect } from "react" ; const useSuggestion = ( url , prop ) => { const [ suggestions ] = useFetch ( url , { cache : true } ) ; const [ data , setData ] = useState ( [ ] ) ; useEffect ( ( ) => { if ( ! suggestions ) return ; const isBug = prop [ 1 ] === 'bugId' ; const suggestionsArray = suggestions . data . map ( ( suggestions ) => { let display = suggestions [ prop [ 0 ] ] ; if ( isBug ) { display = suggestions [ prop [ 0 ] ] + ' #' + suggestions [ prop [ 1 ] ] ; } return { display , id : suggestions [ prop [ 1 ] ] } ; } ) ; setData ( suggestionsArray ) ; } , [ suggestions ] ) ; return data ; } ; export default useSuggestion ;