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

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

JavaScript cps12345 1年前 (2020-09-18) 223次浏览 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)

您必须 登录 才能发表评论!