Consider I have a folder with .md files like this:
/static/blog/
example_title.md
another_example.md
three_examples.md
and I have an array including all titles:
const blogEntries = ["example_title", "another_example", "three_examples"]
in my component I want to import all of them, notice that there could be fewer or more.
Is there any way to dynamically import them similar to:
for (let entry in blogEntries) {
import `Markdown_${entry}` from `/static/blog/${entry}.md`
}
and later in my render I can do:
<Markdown_three_examples />
the above obviously would not work, but I'm looking for a way to achieve similar.
fetch()the md file from the server when it has mounted.componentDidMount(), usefetch()to load the Markdown file. Set its content as part of your state so it gets rendered. Implement the loop by rendering multiple components, using your file array andmap().import(), which is not required to do this at all, and imo takes the question strictly at face value while ignoring the bigger picture. Here's my take: codesandbox.io/s/l2jlq3j78m