ReactJS: Warning: setState(…): Cannot update during an existing state transition

后端 未结 11 1117
一个人的身影
一个人的身影 2020-11-27 10:32

I am trying to refactor the following code from my render view:

11条回答
  •  失恋的感觉
    2020-11-27 10:43

    This same warning will be emitted on any state changes done in a render() call.

    An example of a tricky to find case: When rendering a multi-select GUI component based on state data, if state has nothing to display, a call to resetOptions() is considered state change for that component.

    The obvious fix is to do resetOptions() in componentDidUpdate() instead of render().

提交回复
热议问题