简体   繁体   中英

Does change in each independent state in functional component triggers a render for the component in React?

When we have multiple independent states in a component then if I change any one of them, will it trigger a re-render of the entire component?

Initialise const [email, setEmail] = useState('') const [val, setVal] = useState(true)

Update setVal(false)

Will this render the whole component again?

Yes the Component will be rendered again. Let me add: Although if you have two states changing (almost) simultanously the state update will be batched. In React 18 React batches state updates in React events handlers, promises, setTimeout and native event handlers resulting in only one rerender.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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