Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

reactjs - In REACT, is a rerender always triggered for each state reset individually?

I'm wondering about a fundamental working in REACT. It's relevant to understand whether my code contains racing conditions. I can't really think of an easy test to check how it works.

Assume the following situation.

We have a component X that is the parent of a child component Y.

this.state.x in the component X is given as a property to the component Y.

if we reset this.state.x the component Y will rerender.

Assume that we reset the state of X 3 times sequentially. Say first to 1 then to 2 and then to 3.

If we reset the x to 1 and then while Y is rerendering we set it very quickly to 2 and then 3.

My question is, if we set x to 2 and 3 while Y is still rerendering with x=1, does Y rerender one time with x=2 and one time with x=3 or only one time for x=3?

question from:https://stackoverflow.com/questions/65947270/in-react-is-a-rerender-always-triggered-for-each-state-reset-individually

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...