Skip to content

Commit 71a588b

Browse files
committed
Fix Switch causing RetryableMountingLayerException
1 parent d92ecda commit 71a588b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Libraries/Components/Switch/Switch.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,13 @@ const SwitchWithForwardedRef: React.AbstractComponent<
165165
setNative({value: event.nativeEvent.value});
166166
};
167167

168-
React.useEffect(() => {
168+
React.useLayoutEffect(() => {
169169
// This is necessary in case native updates the switch and JS decides
170170
// that the update should be ignored and we should stick with the value
171171
// that we have in JS.
172172
const jsValue = value === true;
173-
const shouldUpdateNativeSwitch = native.value !== jsValue;
173+
const shouldUpdateNativeSwitch =
174+
native.value != null && native.value !== jsValue;
174175
if (
175176
shouldUpdateNativeSwitch &&
176177
nativeSwitchRef.current?.setNativeProps != null

0 commit comments

Comments
 (0)