简体   繁体   English

Coffeescript-单击后未渲染React setState

[英]Coffeescript - React setState not rendering after click

I am trying to change the text of a button when the user clicks on it. 我试图在用户单击按钮时更改按钮的文本。

The state changes but, the component does not seem to re-render 状态改变了,但是组件似乎没有重新渲染

However, when I put the state in the upper level (in the outer if statement), the components text does change (but it would be in a separate view). 但是,当我将状态放在较高级别(在外部if语句中)时,组件文本确实发生了变化(但它将在单独的视图中)。 I need to keep that component in that else if clause 我需要将该组件保留在else if子句中

Am I missing something or does this not work? 我是否缺少某些东西,或者这不起作用? I am still learning react and don't understand the whole concept of state and the deeper levels of state changes 我仍在学习做出反应,不了解状态的整个概念以及状态变化的更深层次

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
        ...

And in onSelectPlan 并在onSelectPlan

onSelectPlan: (e, plan) ->
    if plan == 0
        @setState planSelected: true

Your "bind" looks wrong. 您的“绑定”看起来不对。 You probably don't need the "bind" at all -- just use a fat arrow: 您可能根本不需要“绑定”-只需使用粗箭头即可:

SelectButton
  clickHandler: (e, plan) =>
    if plan is 0
      @setState planSelected: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM