[英]Coffeescript - React setState not rendering after click
我試圖在用戶單擊按鈕時更改按鈕的文本。
狀態改變了,但是組件似乎沒有重新渲染
但是,當我將狀態放在較高級別(在外部if語句中)時,組件文本確實發生了變化(但它將在單獨的視圖中)。 我需要將該組件保留在else if
子句中
我是否缺少某些東西,或者這不起作用? 我仍在學習做出反應,不了解狀態的整個概念以及狀態變化的更深層次
render: ->
if @state.couponSet == true and @state.couponSuccess != true
div {},
"Some view"
else if @state.couponMode != true and @ state.couponSuccess != true
div { className: "container" },
SelectButton
clickHandler: @onSelectPlan.bind(null, this, 0)
wrapperClassName: 'button-wrapper'
className: 'plan-select'
buttonText: if @state.planSelected == true then "Selected" else "Select"
else
...
並在onSelectPlan
onSelectPlan: (e, plan) ->
if plan == 0
@setState planSelected: true
您的“綁定”看起來不對。 您可能根本不需要“綁定”-只需使用粗箭頭即可:
SelectButton
clickHandler: (e, plan) =>
if plan is 0
@setState planSelected: true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.