Reactjs 位置不变冲突的来源:对象作为React子对象无效(找到:[对象承诺])
堆栈跟踪未指向问题的根源:Reactjs 位置不变冲突的来源:对象作为React子对象无效(找到:[对象承诺]),reactjs,react-native-web,Reactjs,React Native Web,堆栈跟踪未指向问题的根源: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead. in Route (at App.js:84) in Switch (at App.js:78) ... 这表明: App.js:84 但这不是承诺,只是一个简单的js对象 如何
Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.
in Route (at App.js:84)
in Switch (at App.js:78)
...
这表明:
App.js:84
但这不是承诺,只是一个简单的js对象
如何找到错误的来源?
此。onRouteToCallback
是一个异步
函数-当调用一个异步
函数而前面没有等待
时,返回值是一个承诺(毕竟,异步
//code>等待只是承诺的语法糖)
您不能从
路由
渲染道具返回承诺-它必须返回组件。aha!非常感谢。但是当我更改它时:等待这个。onRouteToCallback(props)}/>
我仍然会遇到同样的错误我刚刚发现了一个重复的问题,我认为可以回答这个问题-你不能直接在render prop中进行异步渲染。我从评论中看到了原因——谢谢Joe
<Route path="/callback" render={props => this.onRouteToCallback(props)} />
//...
async onRouteToCallback ({ location }) {
return <View><Text>test</Text></View> // added to debug
_callee4$
src/App.js:122
119 |
120 | console.log('apolloClient', JSON.stringify(apolloClient))
121 |
> 122 | this.setState({ apolloClient })
| ^ 123 | }
124 |
125 | async relayAuthToGraphcool() {