javascript - (reactjs) Include local Images in react component -


i have following component, renders image using html img src=".."

export default class landing extends component{    render() {    return(      <div classname="topimg">        <img src={'test.jpg'}/>     </div> 

but page not display image. folder structure following

/layout/landing.jsx /layour/test.jpg

it works web urls not local files.

not sure how building app attach images component requireing them first. way app knows include image (referenced relatively component) before rendering.

export default class landing extends component {   constructor( props ) {     super(props);      this.images = {       test: require('./test.jpg')     };   }    render() {     return (       <div classname="topimg">         <img src={this.images.test}/>       </div>     );   } } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -