The React Native Settings API appears to be broken in Expo.
I tested by creating new a project using react-native init
. The Settings API works as expected. But when I create a new project using expo init
, I get the following error:
null is not an object (evaluating 'this._settings[key]')
- node_modules/react-native/Libraries/Settings/Settings.ios.js:24:26 in get
* App.js:11:35 in onPress
- node_modules/react-native/Libraries/Components/Touchable/TouchableOpacity.js:235:45 in touchableHandlePress
- node_modules/react-native/Libraries/Components/Touchable/Touchable.js:878:34 in _performSideEffectsForTransition
- ... 21 more stack frames from framework internals
Here is the test code:
import React from 'react';
import { Button, SafeAreaView, Settings } from 'react-native';
export default function App() {
return (
<SafeAreaView>
<Button
title="Test Settings"
onPress={() => {
try {
const v = Settings.get('mykey');
alert(v);
} catch (e) {
console.log(e);
alert(e);
}
}}
/>
</SafeAreaView>
);
}
It appears that NativeSettingsManager
is null here react-native/Settings.ios.js at main · facebook/react-native · GitHub
I wonder if something just needs to be linked in expo?
Others have experienced this as well: