facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.14k stars 24.21k forks source link

fetch is not working in some cases #19115

Closed faustoct1 closed 6 years ago

faustoct1 commented 6 years ago

Fetch is not working on android and ios. It seems when I put everything in the same block it works fine, only after executing each request in a callback inside response. Making a request as soon as the app loads not work when have multiple requests running in parallel. It seems a strange behaviour.

what works for me like all the stuffs in Main.js

    setTimeout(()=>{
      Backend.post('pingserver',{}, (json) => {
        Backend.post('pingserver',{}, (json) => {})
      })
    },10)

what I wanna do in App.js

      Backend.post('pingserver',{}, (json) => {})
      Backend.post('pingserver',{}, (json) => {})

The Backend.js code smth like

      let response = await fetch(
        this.endpoint(endpoint),
        {
          method: 'GET',
          headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
          }
        }
      );
      let json = await response.json();
      if(callback)callback(json)

Environment

Environment: OS: macOS High Sierra 10.13.4 Node: 9.8.0 Yarn: 1.5.1 npm: 5.6.0 Watchman: 4.9.0 Xcode: Xcode 9.3 Build version 9E145 Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed) react: 16.3.0-alpha.1 => 16.3.0-alpha.1 react-native: https://github.com/expo/react-native/archive/sdk-26.0.0.tar.gz => 0.54.2

faustoct1 commented 6 years ago

any workaround?

faustoct1 commented 6 years ago

anyone?

react-native-bot commented 6 years ago

This issue looks like a question that would be best asked on Stack Overflow.

Stack Overflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only.

Will close this as this is really a question that should be asked on Stack Overflow.

faustoct1 commented 6 years ago

any help so far? get back to this issue.. @chirag04 any ideia what's happening here?