user13033942
user13033942

Reputation:

fetch function in react-native does not work

I want to send a http request with fetch function . after calling fetch there is no response and no error . where is my problem ?

this is my component :(this is for sample and I want to test http request in react-native)

const App = () => {

  const changeTextHandler = async text => {
    try {
      const response = await fetch("https://jsonplaceholder.typicode.com/todos/1");
      const result = await response.json();
      console.log(result)
    }
    catch (error) {
      console.log(error)
    }  
  }

  return (
    <View style={styles.container}>
      <TextInput
        onChangeText={changeTextHandler}
        style={styles.textInput} />
    </View>
  )
}

Upvotes: 1

Views: 61

Answers (1)

Anurodh Singh
Anurodh Singh

Reputation: 812

There is nothing wrong with your code. The jsonplaceholder API server might be down because of some reason.

Upvotes: 1

Related Questions