Fetching data from nested array in API React Native

Kay

I'm trying to fetch data from a nested array from an API in react native.

so my coding is like this

export default const App= () =>{

    const [data, setData] = useState([]);
    console.log(data);

     //Some fetch code here
    //setData happen here
  
    return  (
       <View >
        <Text >fetched data</Text>
          <Text>{data?.data?.items?.newOne?.a}</Text>
          <Text>{data?.data?.items?.newOne?.b}</Text>
          <Text>{data?.data?.items?.newOne?.c}</Text>
       </View>
    )
};

and the supposed array is like this

arr = { code: 1, data:{ items:[{newOne:{a:2, b:4, c:6}, id:00},], totality: 1}}

can someone tell me what I'm doing it wrong here? I'm new to js and also react native. I received blank whenever I run this code.

Musa

items is an array, so you have to access it as one

return  (
   <View >
    <Text >fetched data</Text>
      <Text>{data?.data?.items[0]?.newOne?.a}</Text>
      <Text>{data?.data?.items[0]?.newOne?.b}</Text>
      <Text>{data?.data?.items[0]?.newOne?.c}</Text>
   </View>
)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to display the nested array data in react native from API?

fetching nested data from rest countries API using typescript in react

Fetching data from API in react native using redux

Fetching data from api in react

Getting an empty array in React while fetching the data from the api

Fetching list of objects from API react native

Fetching data from api promise in react API

Fetching data from YouTube API with React Hooks

React Router Fetching data from API

Fetching data from api and passing it to state in React

Show all the data from a nested array of objects in React Native

Data's not displaying while fetching from API and using Flatlist in react native

Fetching API data with React

Fetching nested API data to reactjs

How to use nested loops for fetching the data from a rest api in flutter?

Fetching Data From Server Using iOS Device in React Native

setState not working in react native after fetching data from database

App Fetching slowly large number of data from firebase react native

Problem with fetching data to React Native application from express server

React Native fetching data from Firebase does not work

React: following DRY in React when fetching data from API

Fetching API data via React

React.js: Fetching Data from API with Bearer Token

fetching POST data from API (node js, react)

React useEffect infinite loop fetching data from an api

Gettin 'null' while fetching data from api with React Context

Fetching random data from API on button click - React

Applying Filter after Fetching data from api in React

Accessing certain item after fetching data from API with react