Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

store fetch data in variable javascript

import { useState, useEffect } from 'react'

const App = () => {
	const [data, useData] = useState(null);
    useEffect(() => {
    	const url = 'endpoint url';
        fetch(url)
        	.then(res => res.json())
            .then(data => setData(data))
    };
    return (
    	<div id='App'>
        	{ data && <p>data.id</p> }
        </div>
    );
};
export default App
 
PREVIOUS NEXT
Tagged: #store #fetch #data #variable #javascript
ADD COMMENT
Topic
Name
1+8 =