I've read the doc about React.Suspense, it seems great, but how can I use it while performing an api call, with axios for example?
To be more specific, why this code doesn't work?
export default function Foo(){
const [state, setState] = useState()
useEffect(()=> {
axios.get("url")
.then(res=> setState(res.data))
.catch(_=> setState(null)
}, [])
return (
<Suspense fallback="loading data">
<div>hello {state.name}</div>
</Suspense>
)
}
Thanks!