亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

這個地方的react報錯是什么原因呢

這個地方的react報錯是什么原因呢

江戶川亂折騰 2019-03-08 18:15:56
百度了一會兒也沒找到原因 --瀏覽器拋出的錯誤信息是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了一下。為什么會執行了兩遍。第一遍參數是空。第二遍就有了我的對應的參數。。
查看完整描述

2 回答

?
嚕嚕噠

TA貢獻1784條經驗 獲得超7個贊

錯誤提示已經說了:
found: object with keys {},你的render函數里寫的是

<div  >{this.props.reducerCity}</div>

實際上看了你的代碼應該是

<div  >{this.props.reducerCity.cityName}</div>

執行兩邊可能是因為你settimeout修改了state,會導致重新渲染頁面


查看完整回答
反對 回復 2019-03-24
?
慕虎7371278

TA貢獻1802條經驗 獲得超4個贊

問題出在this.props.reducerCity。


查看完整回答
反對 回復 2019-03-24
  • 2 回答
  • 0 關注
  • 874 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號