[英]Is state update in getDerivedStateFromProps synchronous with the render?
由於在每次渲染之前都會調用getDervivedStateFromProps
,因此我假設在渲染之前保證狀態會同步更新(即它不會像其他setState
調用那樣被批量處理,就像普通的setState
調用那樣?)
換句話說, getDerivedStateFromProps
中發生的任何更新都保證會反映在以下render
?
來自React的官方文檔: https : //reactjs.org/docs/react-component.html#static-getderivedstatefromprops
getDerivedStateFromProps在調用render方法之前調用,包括初始安裝和后續更新。 它應返回一個對象來更新狀態,或者返回null以不更新任何內容。
也:
請注意,無論原因如何,都會在每個渲染上觸發此方法。
所以我會說答案是肯定的,但我會避免使用它。 請檢查: https : //reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.