React Native's Controlled Switch Component
The Switch component is a 'controlled' input; it doesn't manage its own state. You use it for on/off settings by telling it what to display via the `value` prop and updating that state in the `onValueChange` callback. The footgun is forgetting this link.
The React Native Switch is a 'controlled component,' meaning it doesn't manage its own on/off state; your app's state is the single source of truth. You use it for boolean settings like 'Enable Dark Mode'. The component renders based on its `value` prop, and when a user taps it, it calls your `onValueChange` function. The common mistake is not using this callback to update the state that feeds the `value` prop, which causes the switch to visually ignore user input.
Read the original → reactnative.dev
- #react-native
- #component
- #state-management
- #ui
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.