React Native Switch Example Tutorial




React Native Switch Example Tutorial

Hi Guys,

In this blog, I will explain you how to create switch in react native. You can easily create switch in react native. First i will import namespace Switch

, after I will make switch using Switch tag in react native.

Here, I will give you full example for simply display switch using react native as bellow.

Step 1 - Create project

In the first step Run the following command for create project.

expo init switch

Step 2 - App.js

In this step, You will open App.js file and put the code.

import React, { useState } from "react";

import { View, Switch, StyleSheet } from "react-native";

export default function App() {

const [isEnabled, setIsEnabled] = useState(false);

const toggleSwitch = () => setIsEnabled(previousState => !previousState);

return (

<View style={styles.container}>


trackColor={{ false: "red", true: "green" }}

thumbColor={isEnabled ? "#f5dd4b" : "#f4f3f4"}








const styles = StyleSheet.create({

container: {

flex: 1,

alignItems: "center",

justifyContent: "center"



Step 3 - Run project

In the last step run your project using bellow command.

npm start


It will help you...

#React Native