How to Create a custom CheckBox Component in React Native?
Last Updated :
11 Jan, 2025
React Native is all about components. It provides many built-in components for us to use. By using this component, we can create a beautiful UI for mobile applications. But it lacks some of the components. And CheckBox is one of them. React Native does not provide any built-in component that we can use as a checkbox. A checkbox is a graphical widget that allows the user to make multiple choices. Users can select multiple checkboxes from the given options at once. Because we don't have any checkbox component in React Native, we will create a custom CheckBox component on our own. Third-party libraries like React-Native-elements also provide checkbox components but by creating our own, we can have more control over its functionality and customization.
Creating Application:
Step 1: Open your Terminal and run the below command. It will install Expo CLI globally in your system.
npm install -g expo-cli
Step 2: Now, create a new React Native Project by running the below command.
expo init "Your_Project_Name"
Step 3: You'll be asked to choose a template. Select blank template.

Step 4: Now go to the project folder and run the below command to start the server.
cd "Your_Project_Name"
Step 5: Create a new file called CheckBox.js. This file is a custom component that we will use to display the checkbox.
touch CheckBox.js
Project Structure: It will look like the following.
CheckBox.js fileApproach: We will create a custom component called CheckBox in React Native. We will write this code in the CheckBox.js file. And then we use this component at every place we want to use the checkbox.
Creating custom components like a CheckBox involves combining React Native components such as TouchableOpacity
and View
for toggling states. Custom styling can be added to match the design.
In this example, we will create a custom CheckBox component. This component we will later use in the main App.js file.
Step 1: Open the CheckBox.js file that we have created earlier. Write below code in that file.
In this file, we will return a view with 2 components. It has one icon for the checkbox and a text for that checkbox. This custom CheckBox will take 3 props.
- title: Text for the checkbox.
- isChecked: Boolean value to show if the checkbox is checked or not. The icon of the checkbox will change according to the isChecked prop.
- onPress: A function that will be called when the user presses that checkbox.
CheckBox.js
import { Pressable, StyleSheet, Text, View } from "react-native";
import React from "react";
import { MaterialCommunityIcons } from "@expo/vector-icons";
const CheckBox = (props) => {
const iconName = props.isChecked ?
"checkbox-marked" : "checkbox-blank-outline";
return (
<View style={styles.container}>
<Pressable onPress={props.onPress}>
<MaterialCommunityIcons
name={iconName} size={24} color="#000" />
</Pressable>
<Text style={styles.title}>{props.title}</Text>
</View>
);
};
export default CheckBox;
const styles = StyleSheet.create({
container: {
justifyContent: "flex-start",
alignItems: "center",
flexDirection: "row",
width: 150,
marginTop: 5,
marginHorizontal: 5,
},
title: {
fontSize: 16,
color: "#000",
marginLeft: 5,
fontWeight: "600",
},
});
Step 2: Open the App.js file and write the below code in that file.
App.js is the main file that renders first when you run your app. In this file, we will use our custom CheckBox component. We will create 3 states for 3 checkboxes. Initially, it will have a boolean value of false. We assign this state to CheckBox's isChecked property. We will also provide a title for each checkbox and a function to check/uncheck the specific checkboxes.
App.js
import { StyleSheet, View } from "react-native";
import { useState } from "react";
import CheckBox from "./CheckBox";
export default function App() {
const [music, setMusic] = useState(false);
const [dancing, setDancing] = useState(false);
const [reading, setReading] = useState(false);
return (
<View style={styles.container}>
<CheckBox
onPress={() => setMusic(!music)}
title="Music"
isChecked={music}
/>
<CheckBox
onPress={() => setDancing(!dancing)}
title="Dancing"
isChecked={dancing}
/>
<CheckBox
onPress={() => setReading(!reading)}
title="Reading"
isChecked={reading}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
justifyContent: "center",
alignItems: "center",
},
});
Output:
This is how you can create a custom CheckBox component in React Native. You can reuse it as many times as you want. And you can customize it according to your requirement.
Similar Reads
How to create a Banner in react-native ?
React Native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render m
3 min read
How to Create Button in React-Native App ?
React Native provides pre-defined components like button and TouchableOpacity to create buttons in a react native app. In this article, we will see how to create buttons in react-native, their syntax, and different types of buttons available in react-native.Table of ContentApproachButton in React Na
4 min read
How to create custom FAB(Floating Action Button) in React Native?
React Native doesn't come with any FAB component built-in. A floating action button (FAB) is used whenever you want to display a button on the top of everything. If you have used ScrollView and the user can scroll up and down, this FAB button will always stay at the same position and doesn't move wi
3 min read
How to Create Calendar App in React Native ?
In this article, we will see how to add a Calendar in React Native App. Discover how to enhance your React Native application by integrating a calendar using the powerful react-native-calendars library. With React Native's ability to facilitate cross-platform mobile app development using JavaScript.
2 min read
How to create a basic button in React Native ?
In this article, we will learn how to create a basic button in React Native. To build a React Native app, we will use the Expo CLI, which provides a smoother experience for running your applications.ExpoIt is a framework and a platform for universal React applications. It is a set of tools and servi
5 min read
How to create a Floating Action Button in react native ?
React Native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render m
2 min read
How to create custom dialog box with text input React Native?
React Native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. In this article, we are going to create a dialog with Text Input. To achieve this we will use React Native's built-in Modal component which we will use as a D
3 min read
How to import components in React Native ?
React Native is a framework developed by Facebook for creating native-style applications for Android & iOS under one common language, i.e. JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can
5 min read
How to create a table in react-native ?
React native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render m
2 min read
How to Create Card with Box Shadow in React Native ?
Creating Card with box shadow in react native makes it stand out within the interface and display information in an appealing way. It will be done in React Native by using the expo cli. Expo simplifies cross-platform app development by providing a unified codebase for iOS, Android, and the web. With
4 min read