How am I failing to update a state variable in ReactJS?

前端 未结 1 1878
Happy的楠姐
Happy的楠姐 2020-12-12 05:53

I have an event handler in ReactJS designed so that when someone clicks the \"Done\" checkbox for a calendar entry, the calendar entry is still in the system but it is marke

相关标签:
1条回答
  • 2020-12-12 06:22

    From the documentation (in a big red box nonetheless):

    setState() does not immediately mutate this.state but creates a pending state transition. Accessing this.state after calling this method can potentially return the existing value.

    and

    The second (optional) parameter is a callback function that will be executed once setState is completed and the component is re-rendered.

    That callback gets passed the updated state afaik.

    0 讨论(0)
提交回复
热议问题