React报错大坑之一:Warning: Functions are not valid as a React child. This may happen if you return a Co...
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.
·
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.
翻译:
方法(函数)作为一个React子组件是无效的。
出现这种情况可能是因为:
①你return一个组件时,错写成Component而不是写成<Component />
②或许你想调用这个函数而不是return它。
这个警告提示没有说出关键问题,实际上是我调用一个方法时忘记加括号,如果小伙伴们有类似报错,可以查查自己是不是在哪里漏了一对括号。
如图红框内,应该改为Math.random():
更多推荐
所有评论(0)