Answers for "load all icon from a folder in react"

0

load all icon from a folder in react

export default App;
import React from 'react';
import ReactDOM from 'react-dom';
var listOfImages =[];

class App extends React.Component{
    importAll(r) {
        return r.keys().map(r);
    }
    componentWillMount() {
        listOfImages = this.importAll(require.context('./images/', false, /\.(png|jpe?g|svg)$/));
    }
    render(){
        return(
          <div>
              {
                    listOfImages.map(
                      (image, index) =>    <img key={index} src={image} alt="info"></img>
                    )
              }
          </div>
        )
    }
}
Posted by: Guest on September-06-2021

Code answers related to "load all icon from a folder in react"

Code answers related to "Javascript"

Browse Popular Code Answers by Language