rotateLogo() fires immediately when isLoading prop gets updated in the following case:
class Logo extends Component {
constructor(props) {
super(props);
};
}
componentDidUpdate() {
if (this.props.isLoading) {
this.rotateLogo();
}
}
...
However, when trying to implement the same in a functional component with useEffect, there is a considerable delay between the update of isLoading and the activation of rotateLogo()
const Logo = ({ isLoading }) => {
useEffect(() => {
if (isLoading) {
rotateLogo();
}
}, [isLoading])
...
在这种情况下,您可能希望同步重新渲染,因此您应该使用useLayoutEffect
而不是useEffect
: https : useEffect
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.