So I am trying to make a react component which calls an API and displays that data in a table. The problem is that when I call the api with fetch, it does not update the d state, but if I print the the data in the fetch call to console, it does indeed appear, it just isn't setting the d state to that data coming from the call. When print d to the console log it says null. I have fetched data from the same API in other parts of my code in the same way as below and works fine but I don't know why it isn't working in this case. I have tried many things like having the d state in the dependency array or just removing that array all together.
const UnusualTable = () => {
const [d, setD] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
if(!d) {
fetch(api_url)
.then((response) => response.json())
.then((data) => setD(data))
.then(console.log(d));
}
setLoading(false);
}, []);
return (
<Grommet full theme={grommet} themeMode="dark">
{ loading != true ? (
<Box>
<Table align="center" margin="small">
.
.
.
);
}