Search code examples
reactjsimportrequire

React - Import dynamically path to pdf file


Firstly, my page will make an http request to an API

API then response an object which have a path: ./assets/sample.pdf

I want to get urlPdf from import urlPdf from response.path

How can I do that ?


Solution

  • Oh super simple. Just const result = require(response.path)