I used context.
const images = require.context('../../../assets/img', true);
loadImage = imageName => (assets(`./${imageName}`).default);
<img src={loadImage("someimage.png")} alt="" />
I don’t know if this is an optimal solution, but it works.
More Related Contents:
- How to download image in reactjs?
- How to avoid using relative path imports (/../../../redux/action/action1) in create-react-app
- Import SVG as a component in Gatsby
- Image elements do not have explicit width and height
- React: Show loading spinner while images load
- Why calling react setState method doesn’t mutate the state immediately?
- Dynamically import images from a directory using webpack
- How to pass params with history.push/Link/Redirect in react-router v4?
- How to get history on react-router v4?
- How to pass params into link using React router v6?
- React Router v4 – How to get current route?
- Understanding the React Hooks ‘exhaustive-deps’ lint rule
- Warning: Each child in a list should have a unique “key” prop
- How to start search only when user stops typing?
- Is using async componentDidMount() good?
- How to use switch statement inside a React component?
- How can I set a cookie in react?
- How to sync props to state using React hooks : setState()
- deploying create-react-app to heroku with express backend returns invalid host header in browser
- Requires Babel “7.0.0-0” but was loaded with “6.26.3”
- Recommended approach for route-based tests within routes of react-router
- Class extends React.Component can’t use getInitialState in React
- react router v6 No routes matched location
- Question mark before dot in javascript / react [duplicate]
- React this.state is undefined?
- How do I type this ‘as’ JSX attribute in TypeScript?
- React 16 warning “warning.js:36 Warning: Did not expect server HTML to contain a in .”
- How to bundle a React app to a subdirectory on a server?
- How do I window removeEventListener using React useEffect
- Cannot find module ‘sass’