load all icon from a folder in react

Solutions on MaxInterview for load all icon from a folder in react by the best coders in the world

showing results for - "load all icon from a folder in react"
Davide
10 Jan 2017
1export default App;
2import React from 'react';
3import ReactDOM from 'react-dom';
4var listOfImages =[];
5
6class App extends React.Component{
7    importAll(r) {
8        return r.keys().map(r);
9    }
10    componentWillMount() {
11        listOfImages = this.importAll(require.context('./images/', false, /\.(png|jpe?g|svg)$/));
12    }
13    render(){
14        return(
15          <div>
16              {
17                    listOfImages.map(
18                      (image, index) =>    <img key={index} src={image} alt="info"></img>
19                    )
20              }
21          </div>
22        )
23    }
24}
25