解决jsx或者tsx语法报错问题:Objects are not valid as a React child (found: object with keys {})

Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead.

{    // 【注意】jsx 的大括号里面一定要放数组  如果不需要放置内容的时候就放 空数组 [] 或者 null   否则会报错 

                    routes.map(ele => (
                        ele.component ?
                            (ele.permission.includes(role) ? <Menu.Item key={ele.id} icon={ele.icon}>
                                <Link to={ele.path}>
                                    {ele.label}
                                </Link>
                            </Menu.Item> : {})   // 不能写{}  如果没有内容的时候要写空数组或者null
                            :
                            <SubMenu key={ele.id} icon={ele.icon} title={ele.label}>
                                {
                                    ele.children && ele.children.map(el => (

                                        el.permission.includes(role) ?
                                            <Menu.Item key={el.id}>
                                                <Link to={el.path}>
                                                    {el.label}
                                                </Link>
                                            </Menu.Item> : null

                                    ))
                                }
                            </SubMenu>
                    ))


                }

你可能感兴趣的:(笔记,bug,react,jsx)