Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Unable to mock API request using miragejs in ReactNative Typescript because window is not defined

$
0
0

I am building a mobile application using ReactNative. My app is interacting with an API. I am trying to mock the API requests using Mirage JS when I am building the app locally following this link, https://miragejs.com/quickstarts/react-native/development/. I basically installed miragejs and copied the code from the link into App.tsx file.

This is my code.

if (window.server) {  server.shutdown()}window.server = createServer({  routes() {    this.get("/api/movies", () => {      return {        movies: [          { id: 1, name: "Inception", year: 2010 },          { id: 2, name: "Interstellar", year: 2014 },          { id: 3, name: "Dunkirk", year: 2017 },        ],      }    })  },})

I am getting the following compilation error in the IDE.

enter image description here

How can I fix it?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>