我正在尝试在axios的成功函数中调用setState,我收到了以下错误:
Uncaught TypeError: existingChildren.set is not a function
at mapRemainingChildren (react-dom.development.js:6824)
at reconcileChildrenArray (react-dom.development.js:7320)
at reconcileChildFibers (react-dom.development.js:7672)
at reconcileChildrenAtExpirationTime (react-dom.development.js:7788)
at reconcileChildren (react-dom.development.js:7771)
at updateHostComponent (react-dom.development.js:8024)
at beginWork (react-dom.development.js:8257)
at performUnitOfWork (react-dom.development.js:10244)
at workLoop (react-dom.development.js:10308)
at HTMLUnknownElement.callCallback (react-dom.development.js:540)
at Object.invokeGuardedCallbackDev (react-dom.development.js:579)
at invokeGuardedCallback (react-dom.development.js:436)
at renderRoot (react-dom.development.js:10386)
at performWorkOnRoot (react-dom.development.js:11000)
at performWork (react-dom.development.js:10952)
at requestWork (react-dom.development.js:10861)
at scheduleWorkImpl (react-dom.development.js:10744)
at scheduleWork (react-dom.development.js:10706)
at Object.enqueueSetState (react-dom.development.js:6204)
at App../node_modules/react/cjs/react.development.js.Component.setState
(react.development.js:226)
at App.js:86
at <anonymous>
这是生成错误的代码:
componentDidMount() {
axios
.get('/api/fetchMapData')
.then(
function(response) {
this.setState({ mapData: response.data });
}.bind(this)
)
.catch(function(error) {
console.log(error);
});
}
我认为这与我渲染导致问题的组件的方式有关。
render() {
return (
<div className="app">
<Header />
<BreadCrumb
data={this.state.breadCrumb}
setCountryView={this.setCountryView.bind(this)}
/>
<Switch>
<Route
exact
path="/"
component={() =>
<Home
setMapView={this.setMapView.bind(this)}
mapData={this.state.mapData}
/>}
/>
<Route path="/country/:country" component={Country} />
</Switch>
</div>
);
对此有任何建议都非常感谢。