import { useState } from 'react' ; interface UsePeoplesHook { ( ) : { fetchPeoples : ( search : string ) => Promise < void > ; peoples : { name : string ; } [ ] ; } ; } export const usePeoples = ( ) => { const [ peoples , setPeoples ] = useState ( [ ] ) ; const fetchPeoples = async ( search ) => { try { const searchedPeoples = await fetch ( `https://swapi.dev/api/people/?search=${ search }` ) ; const data = await searchedPeoples . json ( ) ; setPeoples ( data . results ) ; } catch ( error ) { console . log ( error ) ; } } ; return { fetchPeoples , peoples } ; } ;