useEffect and load async data in React

I spent a lot of time to understand how to get async data from web-services and to set it to vars in React

I need to try to change 'fetch' to 'axios'

const host =   'https://localhost:7245/api/MySrv/'; //returns the array of data

const [items, setItems] = useState({});

useEffect( () => {
    async function sendRequest() {
        try {
            const response = await fetch(host);
            const json = await response.json();
            setItems( x=> x.title));
        catch (err) {
}, [])

To display use in 'return' this string:


No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment Notes of web-specialist
Since 2009