首页 > 其他分享 >React报错之React.Children.only expected to receive single React element child

React报错之React.Children.only expected to receive single React element child

时间:2022-12-21 22:34:31浏览次数:43  
标签:console receive Button React only 报错 return Children

总览

当我们把多个子元素传递给一个只期望有一个React子元素的组件时,会产生"React.Children.only expected to receive single React element child"错误。为了解决该错误,将所有元素包装在一个React片段或一个封闭div中。

react-children-only-expected-receive-single-child.png

这里有个示例来展示错误是如何发生的。

// App.js

import React from 'react';

function Button(props) {
  // 

标签:console,receive,Button,React,only,报错,return,Children
From: https://www.cnblogs.com/chuckQu/p/16997381.html

相关文章