SWEBDEV Telegram 2985
Оптимизация рендеринга с React.PureComponent

React.PureComponent — это специальный тип компонента в React, который оптимизирует рендеринг за счет автоматического выполнения поверхностного сравнения пропсов и состояния.

В отличие от обычного React.Component, он реализует метод shouldComponentUpdate с поверхностным сравнением пропсов и состояния.

Пример использования:

PureComponent.
class PureComp extends React.PureComponent {
render() {
console.log('PureComponent render');
return <div>{this.props.value}</div>;
}
}


Родительский компонент.
class ParentComponent extends React.Component {
state = {
value: 0
};

componentDidMount() {
setInterval(() => {
this.setState({ value: this.state.value + 1 });
}, 1000);
}

render() {
return (
<div>
<RegularComponent value={this.state.value} />
<PureComp value={this.state.value} />
</div>
);
}
}


👉 @sWebDev
👍4



tgoop.com/sWebDev/2985
Create:
Last Update:

Оптимизация рендеринга с React.PureComponent

React.PureComponent — это специальный тип компонента в React, который оптимизирует рендеринг за счет автоматического выполнения поверхностного сравнения пропсов и состояния.

В отличие от обычного React.Component, он реализует метод shouldComponentUpdate с поверхностным сравнением пропсов и состояния.

Пример использования:

PureComponent.

class PureComp extends React.PureComponent {
render() {
console.log('PureComponent render');
return <div>{this.props.value}</div>;
}
}


Родительский компонент.
class ParentComponent extends React.Component {
state = {
value: 0
};

componentDidMount() {
setInterval(() => {
this.setState({ value: this.state.value + 1 });
}, 1000);
}

render() {
return (
<div>
<RegularComponent value={this.state.value} />
<PureComp value={this.state.value} />
</div>
);
}
}


👉 @sWebDev

BY Frontender Libs - обзор библиотек JS / CSS




Share with your friend now:
tgoop.com/sWebDev/2985

View MORE
Open in Telegram


Telegram News

Date: |

How to Create a Private or Public Channel on Telegram? The group’s featured image is of a Pepe frog yelling, often referred to as the “REEEEEEE” meme. Pepe the Frog was created back in 2005 by Matt Furie and has since become an internet symbol for meme culture and “degen” culture. How to build a private or public channel on Telegram? The main design elements of your Telegram channel include a name, bio (brief description), and avatar. Your bio should be: On June 7, Perekopsky met with Brazilian President Jair Bolsonaro, an avid user of the platform. According to the firm's VP, the main subject of the meeting was "freedom of expression."
from us


Telegram Frontender Libs - обзор библиотек JS / CSS
FROM American