• 赚钱入口【需求资源】限时招募流量主、渠道主,站长合作;【合作模式】CPS长期分成,一次推广永久有收益。主动打款,不扣量;

无法在React中从父类访问属性

JavaScript cps12345 1个月前 (09-18) 43次浏览 0个评论
So i passed some property from parent class(Counters) to child class (counter)

The way i am passing properties

and i think it has been correctly passed down i printed “this.props” on console

but the thing when i am trying to access value of counter via this.props.counter.value it’s throwing error and also when i am trying to console “this.props.counter” it is showing “undefined”

解决

You should use properties as follow:

{this.props.counters.map((counter) => 
  <Counter
    key={counter.id}
    onDelete={this.props.onDelete}
    onIncrement={this.props.onIncrement}
    counter={counter}
  ></Counter>
}

You have prematurly closed <Counter

喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址