Set state with same value using hooks will cause a rerender?
问题 Using hooks, If I call setState with the same value as the state , will it rerender the component? If yes, how can I avoid that? e.g. const [state, setState] = useState(foo) ... // any where in the code setState(foo) Considering that foo can be any thing, such as {} , true , props.bar or a variable from out side of the component (constant). 回答1: It won't re-render the component if you call setState with the same value. Try this out: import React, { useState, useEffect } from "react"; const