解决React报错Functions are not valid as a React child
Borislav Hadzhiev 人气:0总览
产生"Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render."错误
通常是因为以下两个原因:
- 从
render
中返回一个函数引用而不是一个组件。 - 使用 react router 路由作为
<Route path="/about" element={About} />
,而不是<Route path="/about" element={<About />} />
。
这里有个例子来展示错误是如何发生的。
// App.js /** * ⛔️ 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. */ const App = () => { const getButton = () => { return <button>Click</button>; }; //
加载全部内容
- 猜你喜欢
- 用户评论