[英]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.