It appears that there may be an unhandled promise rejection for a request with ID 0, specifically a typeerror indicating that the body

import React from 'react';
import { FlatList, ActivityIndicator, Text, View  } from 'react-native';

export default class DataFetcher extends React.Component {

  constructor(props){
    super(props);
    this.state ={ isLoading: true}
  }

  componentDidMount(){

        fetch('https://apitest.kuveytturk.com.tr/prep/v1/data/fecs', {
             method: 'GET',
             headers: {
               Accept: 'application/json',
               'Content-Type': 'application/json',
             },
             body: JSON.stringify({
               firstParam: 'isoCode ',
               secondParam: 'internationalCode',
               thirdParam: 'name',
               fourthParam: 'code',
               FifthParam: 'group',
               SixthParam: 'id'
             }),
           });

}


  render(){

    if(this.state.isLoading){
      return(
        <View style={{flex: 1, padding: 20}}>
          <ActivityIndicator/>
        </View>
      )
    }

    return(
      <View style={{flex: 1, paddingTop:20}}>
        <FlatList
          data={this.state.dataSource}
          renderItem={({item}) => <Text>{item.isoCode}, {item.internationalCode}, {item.name}, {item.code}, {item.group}</Text>}
          keyExtractor={({id}, index) => id}
        />
      </View>
    );
  }
}

I am learning how to use React Native and I'm attempting to retrieve data from an API. However, I encountered an error with the code.

I received a possible unhandled promise rejection (ID 0) - TypeError: Undefined is not an object.

I am puzzled by why there is no object being returned.

I would greatly appreciate any assistance or guidance on this matter.

Answer №1

It's important to remember that in a GET Request, you cannot use the body parameter. Make sure to switch it to a POST request instead.

Answer №2

When making a GET request, it is not possible to use the body. To pass parameters with a GET request, the official method is to add them to the URL directly. Here's an example:

var url = new URL("https://apitest.kuveytturk.com.tr/prep/v1/data/fecs"),
    params = {firstParam: 'isoCode ',
               secondParam: 'internationalCode',
               thirdParam: 'name',
               fourthParam: 'code',
               FifthParam: 'group',
               SixthParam: 'id'}
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]))
fetch(url).then(/* … */)

Answer №3

It is not recommended to use the body in a GET request. However, you can transform your JSON object into URL query parameters by following this method.

let url += '?'+Object.keys(parameters).map((key) => (key + '=' + encodeURIComponent(parameters[key]))).join('&')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the significance of the double exclamation mark operator in determining the truthiness or falsiness of an object's values?

Trying to determine the truthiness or falsiness of an object is proving to be a challenge for me. If an object contains all truthy values, I want one outcome; if it contains falsy values such as 0, an empty string, or undefined, I want a different outcom ...

Removing an Element According to Screen Size: A Step-by-Step Guide

Currently, I am facing a dilemma with two forms that need to share the same IDs. One form is designed for mobile viewing while the other is for all other devices. Despite using media queries and display: none to toggle their visibility, both forms are stil ...

Issue: Bidirectional binding functionality is not functioning properly within the user interface modal

I'm currently working on displaying data in a modal, but I'm facing issues with getting two-way binding to work properly. In my HTML code: <div class="cta-actions"> <div class="action"><a class="btn btn-lg btn-max">Send a pa ...

Mean stack authentication issue: missing token

Overview: Currently, I'm in the process of developing an application that utilizes node/express for the backend, mongo as the database, and angular for the frontend. User authentication is handled through jsonwebtoken, where a token is stored in local ...

Duplicate the array of objects and make alterations without affecting the original array

I have an array of objects that I need to deep copy and make modifications to each object without altering the original array or its contents. Here is my approach in JavaScript, but I am open to suggestions on a better method. const users = [ { ...

Having trouble sending a POST request to an Endpoint with Formidable and Request

I am encountering an issue while attempting a basic file upload to a REST endpoint using Node. The error that keeps appearing is: TypeError: Cannot read property 'hasOwnProperty' of null Below is my form setup: <form action="/upload4" me ...

Locate a specific text within a complex array of objects and retrieve the objects that contain the match as

I have an array of objects named input as shown below. Each object in the array contains a property vertical of type string, an array called platformList, and a nested object named radar_metadata. I am looking to implement a search functionality where I c ...

Problem with Jquery Sticky Navigation

I've been struggling to understand this issue and can't seem to find any help. http://fiddle.jshell.net/DQgkE/7/show/ The user experience is currently a bit glitchy, but what I would like is: 1) When scrolling down the page, I want the Sticky ...

Stop Google Charts from magnifying the view

I'm currently working on creating a column chart using Google Charts. The purpose of this chart is to display the number of pageviews for a specific page within the last 30 days. Below is the JavaScript code I used to create the chart (you can access ...

Utilizing dotenv: Incorporating the value of one environment variable into the name and value of another environment variable

When it comes to my testing framework, I rely on dotenv for handling environment variables across different test environments. Currenty, I'm looking for a way to incorporate the value of a specific environment variable into both the value and name of ...

Error message: "Root resolution error encountered". Need assistance in granting watchman access?

After setting up a react-native starter project, I was prompted to allow watchman access to my system's files. Unfortunately, I declined and now whenever I try to run the folder, I encounter the following error: Error: unable to resolve root /Users/ck ...

Ways to swap webpack-dev-server for alternative servers such as express or apache

After using vue-cli to scaffold a Vue app, I am looking to set up a new web server instead of webpack-dev-server. I am interested in having a separate configuration file to customize the server settings, similar to using Node Express for production deploym ...

Resizing tables dynamically using HTML and JavaScript

I am attempting to reproduce the functionality demonstrated in this example When dealing with a large table, I want it to resize to display 10 entries and paginate them accordingly. The only thing I require is the pagination feature without the search bar ...

Leveraging personalized AngularJS directives in conjunction with ExpressJS routing

I built my own AngularJS application following a tutorial at . However, I encountered an issue when trying to integrate it with an ExpressJS/Node backend. The tutorial only covers a single view with a single controller, while my Angular app includes multip ...

In the android datePicker dialog, the month is being displayed in conjunction with the letter M and a corresponding

I am attempting to showcase the date in a datePicker dialog in the format Sep|29|2016, as shown in the image below. Expected output https://i.sstatic.net/9iks1.jpg Unfortunately, most of the time I am receiving 28|M09|2016 instead of the expected output ...

Is there a way for me to respond to an APNS push notification by executing a task specified in the payload?

As a newcomer to objective-c, xcode, and app development, I kindly ask for your patience. I have managed to send a push notification via APNS to my new app. I can view the JSON message and log it using NSSLog. Payload: { aps = { alert = { ...

The process of executing a PHP file from JavaScript using XMLHttpRequest is experiencing issues on a XAMPP local server

I'm attempting to execute a PHP file using JavaScript. I have my XAMPP server set up and all files saved in the htdocs folder. The PHP file is also stored in the htdocs folder and works correctly when accessed via http://localhost/php_test.php in Chro ...

Displaying Values/Marks in a Unique Order with Material-UI Slider Component

The default behavior of the Material-UI slider is to display marks/values in ascending order from min to max For instance, if you have a slider configured like this: const marks = [ { value: 1, label: '1' }, { value: 2, lab ...

In the realm of Express JS, there are two applications communicating with each other for

I'm having trouble with the code below - it's not returning a response. Can anyone suggest what might be causing this issue? var express = require('express'), app1 = express(), app2 = express(); app1.use(function(req, res, ne ...

convert byte array to integer array from preview frame

When working with the preview frame, I receive a byte[] in ImageFormat.RGB_565 format. My goal is to convert this byte[] to int[] so that I can perform some pixel manipulation. How can I achieve this efficiently? Currently, my approach looks like this: p ...