What is a Switch component used for in React Native?
A Switch is used to toggle between two states, like ON and OFF, similar to a light switch in real life. It is often used for settings that can be enabled or disabled.
Click to reveal answer
beginner
How does a Checkbox differ from a Switch in mobile apps?
A Checkbox allows multiple selections and shows a checkmark when selected. A Switch is usually for a single binary choice. Checkboxes are often used in lists or forms.
Click to reveal answer
beginner
Which React Native component is used to create a toggle switch?
The Switch component is used to create a toggle switch in React Native.
Click to reveal answer
intermediate
How do you handle the state of a Switch or Checkbox in React Native?
You use React's useState hook to keep track of whether the Switch or Checkbox is ON or OFF, and update the state when the user toggles it.
Click to reveal answer
intermediate
Why is accessibility important for Switch and Checkbox components?
Accessibility ensures that all users, including those using screen readers or keyboard navigation, can understand and interact with the Switch or Checkbox. This includes proper labels and focus management.
Click to reveal answer
Which React Native component is best for a binary ON/OFF setting?
AButton
BCheckbox
CTextInput
DSwitch
✗ Incorrect
The Switch component is designed for binary ON/OFF toggles.
What hook is commonly used to manage the state of a Switch in React Native?
AuseState
BuseEffect
CuseContext
DuseRef
✗ Incorrect
useState is used to store and update the toggle state.
Which property controls the current value of a Switch in React Native?
Aselected
Bchecked
Cvalue
DonValueChange
✗ Incorrect
The 'value' prop sets whether the Switch is ON (true) or OFF (false).
What visual indicator does a Checkbox show when selected?
AA toggle switch
BA checkmark
CA filled circle
DA cross mark
✗ Incorrect
Checkboxes show a checkmark when selected.
Why should Switch and Checkbox components have accessible labels?
ATo help screen reader users understand their purpose
BTo prevent user clicks
CTo change colors automatically
DTo improve app speed
✗ Incorrect
Accessible labels help users with disabilities know what the control does.
Explain how you would implement a Switch in React Native to toggle a setting.
Think about how to store the ON/OFF state and update it when the user taps the switch.
You got /4 concepts.
Describe the differences between Switch and Checkbox components and when to use each.
Consider real-life examples like turning a light on/off versus selecting multiple items in a list.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a Switch component in React Native?
easy
A. To toggle between two states like ON and OFF
B. To select multiple options from a list
C. To input text from the user
D. To display images in a gallery
Solution
Step 1: Understand the Switch component
A Switch is a UI element that lets users toggle between two states, usually ON or OFF.
Step 2: Compare with other components
Checkboxes allow multiple selections, text inputs accept text, and image galleries display images, so these do not match the Switch's purpose.
Final Answer:
To toggle between two states like ON and OFF -> Option A
Quick Check:
Switch toggles states = B [OK]
Hint: Switch means ON/OFF toggle, not multiple selections [OK]
Common Mistakes:
Confusing Switch with Checkbox
Thinking Switch accepts text input
Assuming Switch displays images
2. Which of the following is the correct way to declare a controlled Switch component in React Native?
easy
A. setIsOn(!isOn)} />
B. setIsOn(!isOn)} />
C. setIsOn(!isOn)} />
D. setIsOn(!isOn)} />
Solution
Step 1: Recall Switch props in React Native
The Switch component uses value to set its state and onValueChange as the event handler for toggling.
Step 2: Identify correct syntax
Options using checked or onChange are incorrect because React Native Switch does not use these props.
Final Answer:
<Switch value={isOn} onValueChange={() => setIsOn(!isOn)} /> -> Option D
Quick Check:
Switch uses value and onValueChange = C [OK]
Hint: Switch uses value and onValueChange props [OK]
Common Mistakes:
Using checked instead of value
Using onChange instead of onValueChange
Mixing HTML input props with React Native Switch
3. What will be the output on the screen after running this React Native code snippet?
The Switch component uses onValueChange to handle toggle events, not onChange.
Step 2: Verify other parts
The initial state is declared, value is correct, and React import is assumed correct.
Final Answer:
Using onChange instead of onValueChange -> Option C
Quick Check:
Switch needs onValueChange, not onChange [OK]
Hint: Switch uses onValueChange, not onChange [OK]
Common Mistakes:
Using onChange event instead of onValueChange
Confusing value and checked props
Forgetting to declare state
5. You want to create a list of three checkboxes in React Native where only one can be selected at a time (like radio buttons). Which approach correctly implements this behavior?
hard
A. Use three CheckBox components sharing one state variable that stores the selected option
B. Use one CheckBox component and change its label dynamically
C. Use three CheckBox components each with its own boolean state variable
D. Use three Switch components each with independent state variables
Solution
Step 1: Understand single selection requirement
Only one checkbox can be selected at a time, so all must share one state that tracks which is selected.
Step 2: Evaluate options
Use three CheckBox components sharing one state variable that stores the selected option. This uses one state variable to store the selected option and updates it on selection, ensuring only one is selected. Options A and C use independent states allowing multiple selections. Use one CheckBox component and change its label dynamically uses only one checkbox, which cannot represent three options.
Final Answer:
Use three CheckBox components sharing one state variable that stores the selected option -> Option A
Quick Check:
Single selection needs shared state = D [OK]
Hint: Single selection means one state tracks selected checkbox [OK]
Common Mistakes:
Giving each checkbox its own state allowing multiple selections
Using Switch instead of CheckBox for selection list
Trying to reuse one checkbox for multiple options
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.