Open In App

React Native Image Component

In this article, We are going to see how to add images in react-native. For this, we are going to use the Image component. It is used to add images in react-native.

Syntax:



<Image
  source={}
/>

Props in Image:

Methods in Image:



Now let’s start with the implementation:

Project Structure: It will look like the following.

Example: Now let’s implement the Image. Here we created a button when someone clicks on that button image will show.

App.js




import React , {useState} from 'react';
import { StyleSheet, View ,Image , Button } from 'react-native';
export default function App() {
  const [image , setImage] = useState(false);
  return (
    <View style={styles.container}>
      <View style={!image && styles.image}>
        <Image source=
{require('E:/Projects/react-native-gfg/myapp/images/download.png')}
        />
      </View>
      <Button
        title={"click"}
        onPress={()=>{setImage(!image)}}
      />
    </View>
  );
}
  
const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  image : {
    display : "none",
  }
});

Start the server by using the following command.

npm run android

Output: If your emulator did not open automatically then you need to do it manually. First, go to your android studio and run the emulator. Now start the server again. 

Reference: https://reactnative.dev/docs/image


Article Tags :