Custom component delayed rendering causes issue when building the static pages #4333
-
Hi, I've created a question on Stack overflow and on discord with no success :(. Here is my problem. I have a custom component that loads data from a CSV file and render them as tables with mathjax styling in it. Since this process is asynchronous, the first time the component is rendered no data has yet been retrieved and thus the component renders no data . Then a few milliseconds later the table renders and all is good under However when doing Am I missing a configuration option somewhere ? or something obvious? I'm far from being proficient in react. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Docusaurus produce the static pages without waiting for any fetch to complete. No componentDidMount or useEffect are run during this process. If you want to provide data fetched from an API, you have 2 choices:
If you want to ensure that Docusaurus has the data, you could just fetch that data ahead of time in a build step, like fetch a json file in We'll allow later to have an async config file, that would be able to fetch remote data and pass it to your site using You can also create a plugin for that, in which case you can fetch the data on But the simplest is really to fetch the data before build: |
Beta Was this translation helpful? Give feedback.
Docusaurus produce the static pages without waiting for any fetch to complete. No componentDidMount or useEffect are run during this process.
If you want to provide data fetched from an API, you have 2 choices:
If you want to ensure that Docusaurus has the data, you could just fetch that data ahead of time in a build step, like fetch a json file in
website/data/myData.json
, and import it with@site/data/myData.json
.We'll allow later to have an async config file, that would be able to fetch remote data and pass it to your site using
config.customFields
You can also create a plugin for that, …