Async data will not render
See original GitHub issueHi,
Great package btw! I’m having some issues with rendering when it comes to async data.
I’m trying to render the following:
const InfoDisplay = () => {
const [data, setData] = useState({});
useEffect(() => {
async function fetchInfo() {
const result = await axios
.get(`${API_URI}/info`)
.then((resp) => resp.data)
.catch((err) => [{
error: err.response,
}]);
setData(result);
}
fetchInfo();
}, []);
return (
<>
<TextLoop>
{
Object.keys(data).map((index) => {
return <InfoDisplayItem key={index} data={data[index]} />
})
}
</TextLoop>{" "}
</>
);
};
But nothing shows. However when I either remove the <TextLoop><TextLoop>
or just use some of the examples given in the README I see stuff rendering. Any ideas why async data won’t render?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
React not rendering element if async call for data takes too long
I'm grabbing user data from an API. The API call takes a while. But even when the frontend gets the response, React never...
Read more >How To Handle Async Data Loading, Lazy Loading, and Code ...
Notice that the component renders before the data is loaded. The advantage with asynchronous code is that it won't block the initial render....
Read more >Async waits in React Testing Library - Reflect.run
We receive and render the asynchronous data. We display an error message when data could not be fetched. The loading text initially appears ......
Read more >Data Fetching - Nuxt
asyncData is only available for pages and you don't have access to this inside the hook. ... Unlike fetch , the promise returned...
Read more >Update on Async Rendering – React Blog
In practice this was never true because React has always executed render immediately after componentWillMount . If the data is not available by ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @exsesx !
This worked perfectly. 😄
Thanks for replying @exsesx! I haven’t had the chance to look into this yet @emilnewel, I’ll probably do that over the weekend but for now you can use what @exsesx is suggesting.
This seems to be related with how the new child elements are added to the component but can’t know for sure without digging in the code.