Requiring images with dynamic paths
See original GitHub issueIs it possible to require images with dynamically created paths? E.g.:
import React from 'react';
export default ({ imgName }) => (
<div>
<img src={require(`./images/${imgName}`)} />
</div>
);
Something along the lines described in this article https://medium.com/@bogdan_plieshka/loading-static-and-dynamic-images-with-webpack-8a933e82cb1e
Thanks for any help!
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
React Native - Image Require Module using Dynamic ...
This is exactly what I was looking for. I am creating a local "data" file in my app and I needed to access...
Read more >Static VS Dynamic Images Paths in VUE3 | CodeX - Medium
The requirement for this part is to show the right picture in a list of team members. Different pictures need to be allocated...
Read more >Using dynamic image paths in .vue files - Mitya.uk
A common issue when using frameworks like Nuxt or Vue CLI comes when using dynamic image paths. This is essentially due to Webpack....
Read more >Import images dynamically using require.context - MeloSpace
After researching more, I realised that require only work with static paths (i.e. a hardcoded path instead of a path stored in a...
Read more >next/image - Next.js
Enable Image Optimization with the built-in Image component. ... Dynamic API Routes ... The <Image /> component requires the following properties.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ran in to this problem earlier. I was unable to use a totally dynamic path.
This didn’t work:
But this did work:
Also relevant if you’re using dynamic paths: https://github.com/cyrilwanner/next-optimized-images/issues/141#issuecomment-623556804
This works great, how can I get this to work with query parameters (
?webp
), the following does not seem to work: