Home > Net >  FLatlist dose'nt render at all
FLatlist dose'nt render at all

Time:10-17

I'm trying to make 2 tabs in which each will render a different flatlist on their own, but for some reason, after I pass my API data to a state ('apidata') it won't render flatlist while I can see a log of ApiData's objects. Can anybody observe my problem with rendering data?

here is the sample of data

Object {
  "0": Object {
    "comment": "",
    "end_time": "2021-09-04T11:59:03Z",
    "enter": "49000.00000000",
    "exchange": "BINANCE",
    "leverage": 120,
    "name": "Bitcoin",
    "per": "USDT",
    "position": "LONG",
    "risk_level": "Crazy",
    "stop_loss": "48700.00000000",
    "symbol": "BTC",
    "target_1": "52700.00000000",
    "target_2": "68000.00000000",
    "target_3": "0.00000000",
  },
  "1": Object {
    "comment": "",
    "end_time": "2021-09-14T06:00:00Z",
    "enter": "495000.00000000",
    "exchange": "binanace",
    "leverage": 15,
    "name": "Bitcoin",
    "per": "btc/usdt",
    "position": "LONG",
    "risk_level": "High",
    "stop_loss": "48000.00000000",
    "symbol": "btc",
    "target_1": "52000.00000000",
    "target_2": "5300.00000000",
    "target_3": "0.00000000",
  },

and here is my code which I tried Hi to see if my const works after I tap on its tab.

const Crypto = (apidata) => {
  console.log(apidata, "log e crypto");
  return (
    <View
      style={{
        backgroundColor: "red",
        justifyContent: "center",
        width: "100%",
        height: "100%",
      }}
    >
      <Text style={{ color: "white" }}>Hi</Text>

      <FlatList
        data={apidata}
        scrollEnabled
        keyExtractor={apidata?.risk_level}
        renderItem={(item) => {
          return <Text style={{ color: "white" }}>{apidata?.stop_loss}</Text>;
        }}
      />

CodePudding user response:

FlatList receives an Array of data not an object of objects. Consider transforming the data received from the api to an array of objects.

  • Related