So I have this pdf file import link:
import pdf from '../Files/file-1.pdf'
but I want that name of the file "file-1" to be a variable cause its gonna change from one user to another so is it possible to do pass a variable in the path something like:
const filename = "file-1.pdf"
import pdf from `../File/${filename}` /*ofc this method doesn't
work for many reasons but I just wanted to explain my question*/
CodePudding user response:
This SO Thread might help.
From Thread:
I've got the answer. I can use require to import files dynamically.
const dynamicFile = require('../somepath/' someVar);