Objects are not valid as a React child. If you meant to render a collection of children, use an array instead

前端 未结 11 2592
悲&欢浪女
悲&欢浪女 2020-11-28 07:28

I am setting up a React app with a Rails backend. I am getting the error \"Objects are not valid as a React child (found: object with keys {id, name, info, created_at, updat

11条回答
  •  野性不改
    2020-11-28 07:43

    Had the same issue, In my case I had 1. Parse the string into Json 2. Ensure that when I render my view does not try to display the whole object, but object.value

    data = [
    {
        "id": 1,
        "name": "Home Page",
        "info": "This little bit of info is being loaded from a Rails 
        API.",
        "created_at": "2018-09-18T16:39:22.184Z",
        "updated_at": "2018-09-18T16:39:22.184Z"
    }];
    var jsonData = JSON.parse(data)
    

    Then my view

    return (
    
       }
        keyExtractor={item => item.id}
      />
    );
    

    Because I'm using an array, I used flat list to display, and ensured I work with object.value, not object otherwise you'll get the same issue

提交回复
热议问题