0

I am currently using React and Next.js and next-images to import images

I want to pass data and directly receive it in my img src url like below:

<img src={require(`../src/image/${data}`)} />

But it seems like the backtick and the template string? don't seem to work in the img tag's option. Is there any way to receive data directly to the src url?

1
  • 1
    It may easy to find out when you create a sample in stackblitz.com? Commented Aug 3, 2020 at 8:29

1 Answer 1

1

I think what you're looking for is dynamic import statements. Check this link about the import() syntax. For e.g.,

import(`messages_${getLocale()}.js`)

In section 5 (Support for module()) you can check out some ways to make it work for your code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.