react-native

Where to put images in a react-native project?


I am working on a react-native project and we are putting images currently in /images/ folder. Is it a good path for them ? Is there any best practice?

enter image description here


Solution

  • You can add image folder to src(src/image/index.js). Image folder add index.js file create and add whole app image. In index.js file set

    export const IMAGENAME = require('./icon.png'); 
    

    When import image folder

    import { IMAGENAME } from '../image';
    

    Use image:

    <Image source={ IMAGENAME } />
    

    You can add image to image folder and set path to index file. Hope this will help you.