Skip to content Skip to sidebar Skip to footer

Got Unexpected Token Error While Using React-native-system-setting

For enabling location in Phone i used react-native-system-setting . But while using that i got unexpected token error . can some one clarify me , how to use this in react native c

Solution 1:

you should wrap it in constructor() or componentWillMount()

also SystemSetting.switchLocation() should be only call it when the SystemSetting.isLocationEnabled() return false if you want to enable it

importReact, { Component } from"react";
importSystemSettingfrom'react-native-system-setting';


exportdefaultclassPhoneSettingextendsComponent {

constructor() {
 super();
   SystemSetting.isLocationEnabled().then((enable)=>{
  // got error on above lineconst state = enable ? 'On' : 'Off';
    console.log('Current location is ' + state);
   })

  SystemSetting.switchLocation(()=>{
    console.log('switch location successfully');
  })
}
render() {
  var self = this;
  return (
   <View>
    // some content
    </View>
 );
}
}

Post a Comment for "Got Unexpected Token Error While Using React-native-system-setting"