【发布时间】:2020-11-06 11:45:10
【问题描述】:
我正在使用 React,我正在尝试重用一些代码,因为我必须在每个页面上放置一个按钮;所以我将它声明为另一个组件上的函数,我试图在我的一个页面上调用它,但我得到一个错误:
Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
我有组件:
export const whatsappLink = () => {
return (
<a
href=""
className="link-simulator floating"
target="_blank"
>
<i className="fab fa-whatsapp my-float"></i>
</a>
);
};
我在我的渲染中这样调用它:
<div>{whatsappLink}</div>
为什么会出现这个错误?我该怎么称呼它?
【问题讨论】:
-
组件是这样使用的
<whatsappLink /> -
我试过了,但我得到这个错误:whatsappLink /> 使用了不正确的大小写。对 React 组件使用 PascalCase,对 HTML 元素使用小写。还有这个:标签
在这个浏览器中无法识别。如果您打算渲染一个 React 组件,请以大写字母开头。
标签: reactjs href reusability