简体   繁体   English

setState of react不会重新呈现

[英]setState of react won't rerender

This code is supposed to rerender after updating to the state, but that isn't happening sadly it isn't the case 该代码应该在更新为状态后重新呈现,但不幸的是,事实并非如此

the @state get successfully updated but the rerender is missing @state成功更新,但缺少重新渲染

in data[key].data is a array of objects that gets added to array state[key] 在data [key]中。data是对象数组,已添加到array state [key]中

$.get url, {t: key, o: @state[key].length, l: @state[key].length + @state.defaultAmount}, (data) =>
  if key == "allScores"
    data.allScores = data.allScores.data[@props.currentMode]
  $.each data[key].data, (i, o) =>
    @setState (state) =>
      result = {}
      result[key] = state[key].concat(o)
      result

If @state gets successfully updated one time, then my best bet would be that React doesn't see any change in @state values to trigger a re-render . 如果@state一次成功更新,那么我最好的选择是React不会在@state值中看到任何变化来触发re-render

Inspect the values of properties of @state to see if indeed there is a change. 检查@state的属性值,看是否确实有更改。

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

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