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 require
ing 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
Post a Comment