React Native Hooks are special functions that allow you to use state and other React features inside functional components. They eliminate the need for class components and make code simpler, cleaner, and more reusable.
useHooks are imported from the React library and used directly inside functional components. The most common hook is useState, used for managing component state.
// Importing useState hook from react
import React, { useState } from "react";
// Simple React Native component using useState hook
import React, { useState } from "react";
import { View, Text, Button } from "react-native";
const CounterApp = () => {
const [count, setCount] = useState(0);
return (
<View>
<Text>Count: {count}</Text>
<Button title="Increase" onPress={() => setCount(count + 1)} />
</View>
);
};
export default CounterApp;
When the button is pressed, the state variable count increases by 1 and the UI automatically re-renders with the updated value.
This interactive demo simulates how the React Native code above works. Notice how updating the "Internal State" automatically updates the "Phone UI".
useState(0)Clicking Increase calls setCount, updates memory, and triggers a re-render.
useState