Component with component shouldComponentUpdate vs stateless. Performance?

I know that Stateless components are much more convenient to use (in specific scenarios). But since you cannot use shouldComponentUpdate, does this mean that the component will re-render for each attribute? My question is, is it better or not better (Performance-wise) to use a class component with intelligent mustComponentUpdate than to use a stateless component.

Are stateless components the best performance solution? consider this silly example:

const Hello =(props) =>(
       <div>
           <div> {props.hello}</div>
           <div>{props.bye}</div>
       </div>);

against

class Hello extends Component{
    shouldComponentUpdate(nextProps){
        return nextProps.hello !== this.props.hello
    };
    render() {
        const {hello, bye} = this.props;
        return (
            <div>
               <div> {hello}</div>
               <div>{bye}</div>
           </div>
        );
    }
}

, 2 , , ( ), Stateless ?

UPDATE

. ( shouldComponentUpdate), , . , :

  • , PureComponent Component ( , mustComponentUpdate)
  • , , rerender
  • , ( )
+4
1

, shouldComponentUpdate # 5677

mustComponentUpdate (, ) . , , ( ). , , .. . , ( ).

https://github.com/facebook/react/issues/5677#issuecomment-165125151

, ​​ . .

https://github.com/facebook/react/issues/5677#issuecomment-241190513

https://medium.com/missive-app/45-faster-react-functional-components-now-3509a668e69f

, , ! , 6%. , , 45%.

: . / , , , shouldComponentUpdate. . , shouldComponentUpdate , Hello, , , , . PureComponent, Component.

+1

Source: https://habr.com/ru/post/1684110/


All Articles