Hello: i am trying to do a fetch to an endpoint in a react component. The fetch i have is working (all console logs show it is working). since this a function so i can reuse it - i want to return something from it. i tried returning the response but i dont think i have my return in the right place or something else is wrong. here is the log i am referring to:
console.log(response)
and here is the full code:
   const doFetch = (fetchUri) => {   
        
        fetch(fetchUri)
        .then(async response => {
            const data = await response.json();
            // check for error response
            if (!response.ok) {
                // get error message from body or default to response statusText
                const error = (data && data.message) || response.statusText;
                return Promise.reject(error);
            }
            console.log('running fetch')
            console.log(response)
            
            console.log('showing data from fetch')
            console.log(data)
            return(response)
            // this.setState({ totalReactPackages: data.total })
        })
        .catch(error => {
            this.setState({ errorMessage: error.toString() });
            console.error('There was an error!', error);
        });
     
        
    }; 
So I am hoping someone can help me do that 'return' properly. Thanks! Gerard
 
     
    