百度了一會兒也沒找到原因 --瀏覽器拋出的錯誤信息是Uncaught Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of App.import React , { PureComponent,Component } from 'react'import localStore from '../util/localStore.js'import {cityName} from '../config/localStoreCity.js'import { connect } from 'react-redux'import { bindActionCreators } from 'redux'import * as actions from '../actions/action'class App extends React.Component { constructor(props,context){ super(props,context); this.state={ inintdone:false } } render() { return( <div> <div >{this.props.reducerCity}</div> { this.state.inintdone ? this.props.children :<span> 加載中1...</span> } </div> ) } componentDidMount(){ let name = localStore.getItem(cityName) if (name ==null){ name='北京' } setTimeout(()=>{ this.setState({ inintdone :true }) },1000) this.props.action.localCity({ cityName: name, }) }}function mapStateToProps(state){ console.log(state); return state}function mapDispatchToProps(dispatch) { return { action: bindActionCreators(actions, dispatch) }}export default connect( mapStateToProps, mapDispatchToProps)(App)我的想法是dispatch city以后 <div >{this.props.reducerCity}</div> 這里的城市會對應的變化,但是為什么金額會報錯呢。而且我在mapStateToProps這里console了一下。為什么會執行了兩遍。第一遍參數是空。第二遍就有了我的對應的參數。。
這個地方的react報錯是什么原因呢
江戶川亂折騰
2019-03-08 18:15:56