Saya mengambil data menggunakan aksioma sebagai berikut:

{
    "data": {
        "3": {
            "id": 4,
            "value": "FaAlgolia",
            "name": "zaefzaef",
            "profile_id": 4,
            "order": 9000,
            "created_at": "2021-05-17T20:25:03.000000Z",
            "updated_at": "2021-05-17T20:25:03.000000Z",
            "url": "katon",
            "profile": {
                "id": 4,
                "username": "xxxxxxxxx",
                "bio": "zfzefzef",
                "preview": "ssss",
                "address": "zefzef",
                "country": "us",
                "p_color": "#ffffff",
                "s_color": null,
                "logo": "afffable",
                "showlogo": "null",
                "selectedOption": "option2",
                "url": "katon",
                "user_id": 2,
                "created_at": null,
                "updated_at": "2021-05-17T20:28:08.000000Z"
            }
        },
        "4": {
            "id": 5,
            "value": "FaAlipay",
            "name": "azdadzzad",
            "profile_id": 4,
            "order": 9000,
            "created_at": "2021-05-17T20:41:53.000000Z",
            "updated_at": "2021-05-17T20:41:53.000000Z",
            "url": "katon",
            "profile": {
                "id": 4,
                "username": "xxxxxxxxx",
                "bio": "zfzefzef",
                "preview": "ssss",
                "address": "zefzef",
                "country": "us",
                "p_color": "#ffffff",
                "s_color": null,
                "logo": "afffable",
                "showlogo": "null",
                "selectedOption": "option2",
                "url": "katon",
                "user_id": 2,
                "created_at": null,
                "updated_at": "2021-05-17T20:28:08.000000Z"
            }
        }
    }
}

Di Bereaksi :

  const [list, setList] = React.useState([]); 

  useEffect(() => {
    axios
      .get("http://localhost:8000/api/social/profile/katon")
      .then((response) => {
       let test = (response.data.data)
        setList(test)
      })
      .catch((err) => console.log(err));
  }, []);

console.log dari test masukkan deskripsi gambar di siniReact code throw “TypeError: this.props.data.map bukan fungsi” & React JS - Uncaught TypeError: this.props.data.map bukan fungsi dan tidak menemukan jawaban saya.

0
AlyaKra 18 Mei 2021, 15:22

1 menjawab

Jawaban Terbaik

response.data.data Anda adalah objek dan objek tidak memiliki fungsi .map. Anda harus mengonversinya menjadi Array.

Jika Anda hanya menginginkan nilai objek data dan tidak menggunakan kunci (3,4) maka Anda dapat menggunakan

let test = Object.values(response.data.data);
1
Abdullah Razzaki 18 Mei 2021, 12:33