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

前端 未结 11 2599
悲&欢浪女
悲&欢浪女 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:41

    In JavaScript, arrays and collections are different, although they are somewhat similar, but here the react needs an array. You need to create an array from the collection and apply it.

    let homeArray = new Array(homes.length);
    let i = 0
    
    for (var key in homes) {
        homeArray[i] =  homes[key];
        i = i + 1;
    }
    

提交回复
热议问题