score:2
i solved this with the following code:
(iconname) => {
require.ensure([], require => {
require(`../../images/icons/${iconname}.svg`)
})
}
class mycomponent extends component {
state = {
categoryicon: require(`../../images/icons/${this.props.icon}.svg`)
};
reading the webpack docs on code splitting more carefully helped.
Source: stackoverflow.com
Related Query
- How to load images asynchronously with webpack
- How to load image files with webpack file-loader
- How to use images in css with Webpack
- How to load a typings file as text with Webpack and React?
- How can I load multiple images with Next Image from a loop?
- Images are loaded in external library, how to load them with webpack?
- How to render images with webpack + react?
- Webpack 4 - unable to load images with absolute path in src using url-loader
- How to use Webpack to load a static file with a relative path with React?
- Not load images with webpack and react in SSR
- How to fetch data and then perform other tasks asynchronously on load with useEffect (React JS)
- How do I load and link an svg file with webpack 2.2.1?
- How to disable AMD on 4 files and load them in order with webpack
- Flux - How to initially load Store data with asynchronously fetched data
- How to load data from api and load component asynchronously with map function
- How to load images in FB Instant Games correctly with React?
- How to import CSS modules with Typescript, React and Webpack
- how to set up an inline svg with webpack
- How to avoid React loading twice with Webpack when developing
- Load fonts with Webpack and font-face
- How to set up Babel 6 stage 0 with React and Webpack
- how to use webpack to load CDN or external vendor javascript lib in js file, not in html file
- How to configure webpack dev server with react router dom v4?
- How do you send images to node js with Axios?
- How to import an entire folder of SVG images (or how to load them dynamically) into a React Web App?
- How to handle deploys with Webpack code splitting?
- how to setup bootstrap 4 scss with react webpack
- How do I query multiple images with gatsby-image?
- How to use a webpack dynamic import with a variable query string?
- How to load three-orbitcontrols with import syntax?
More Query from same tag
- why did setState not work in this case?
- How to compute and pass array in props?
- Redux a better way to write reducers?
- How can I create a count down number for setTimeout in react
- Add a counter in react
- Link will not change color and get rid of text-decoration
- How to get dependency component element by Enzyme?
- How can you backtrack through indexes of an array if element returned is null
- How to change main content component based on sidebar component in one layout in React js
- React Formik Default value
- Passing ref up to parent in react
- Async/Await a Page Reload in React TypeScript
- CSS empty definition necessary to have the type as specificity selector (material UI in React)
- Gatsby/React Project wont recongnize ssr script tag cloudinary variable also tried with Helmet
- nodemon app crashed after submitting form data
- "Actions must be plain objects. Use custom middleware for async actions." while using redux-thunk
- React, Typescript and Jest - Why is simple test failing
- WebStorm: how to add jsx file type to 'File > New' list
- Only render specific component in a big react project
- how to validate three inputs as if they were only one in ant design?
- Firestore database only works every other time
- react dynamic render with number
- How to send value with route - reactjs
- Displaying repetitive html element with conditional value
- NextJS Image component with fixed witdth and auto height
- Not able to access variables in jest.mock function
- Accordion height automatically increases when any accordion expands in same row mui
- How to mock functions, and test that they're called, when passed as props in react components?
- Component not re-rendering after Context change
- React Typescript how to setState