I've got a question about importing a dynamic file path in reactjs.
I already know, that I can import a file / image like this:
import pdfImage from '../images/pdf.svg';
Now I wanto to import a file from an object given from the props. I have relative file path in my object saved i.e.
documents/1_1_DEU_DE.pdf
The issue is, that on build, the path to the file looks like this i.e. of the pdf image above.
/static/media/pdf.3fa92281.svg
so I'm searching for something similar to this:
render() {
import pdfFile from '../' + this.props.termsAndCondition.pdfDocument;
return (
<li>
<a href={pdfFile} target="_blank">
<img src={pdfImage}></img>
{this.props.termsAndCondition.language}
</a>
</li>
);
}
Of course, I know, I can put the files instead of the src folder to the public folder, but is this recommended?
I'm sure there is a solution to my problem, but all my researches did not get an answer to me.
Thanks in advance.