I would like to debug on my mobile/simulator and point it dynamically to API.
const {manifest} = Expo.Constants;
const api = manifest.packagerOpts.dev
? manifest.debuggerHost.split(':').shift().concat(':3000')
: 'productionurl.com'
export function getEvents(){
return fetch('http://${api}/events')
.then(response => response.json())
.then(events => events.map(e =>({ ...e, date: new Date(e.date)})));
}
I am getting the following error:
undefined is not an object(evaluating'_expo.default.Constants')
I work with "sdkVersion": "35.0.0"
. It seems that Expo changed its API. They extracted and moved some parts into separate packages.
Now for this case you need to install a separate dependency:
npm i --save expo-constants
And then to import FileSystem
object independently for your component:
import Constants from 'expo-constants';