React shouldComponentUpdate()= false不停止重新渲染

bit*_*eam 13 javascript reactjs

基本上,我有这个非常简单的反应组件.它的作用是环绕'react-intercom',只有在状态发生变化时才会渲染它.为了简化问题,我已经将该shouldCompoenentUpdate()方法硬连接以始终返回false.

    import React from 'react';
    import Intercom from 'react-intercom';
    
    class IntercomWrapper extends React.Component {
        shouldComponentUpdate(nextProps, nextState) {
            // console.log(!!nextProps.user && nextProps.user.userId !== this.props.user.userId);
            // return !!nextProps.user && nextProps.user.userId !== this.props.user.userId;
            return false;
        }
    
        render() {
            console.log('rendering');
            return <Intercom {...this.props} />;
        }
    };
    
    export default IntercomWrapper;
Run Code Online (Sandbox Code Playgroud)

会发生什么事情,它总是会重新渲染,这不应该发生.

任何人都知道为什么会发生这种情况?

Sag*_*b.g 2

这不会阻止子组件的渲染:
来自DOCS

返回 false 不会阻止子组件在状态更改时重新渲染。...

请注意,将来 React 可能会将 shouldComponentUpdate() 视为提示而不是严格指令,并且返回 false 仍可能导致组件重新渲染。