I am calling an API and getting the response properly but same response value is showing empty outside the response function. I need to get it from outside while page onload.Code below
Test.js
import React, { useState, useEffect,useRef, useMemo } from 'react';
import axios from 'axios';
function Test() {
const [state, setState] = useState([]);
useEffect(() => {
axios.get(`https://jsonplaceholder.typicode.com/todos/1`)
.then(res => {
setState(res.data);
})
console.log(state)
},
[]);
}
export default Test;