Về cơ bản, tôi đã có thành phần phản ứng khá đơn giản này. Những gì nó làm là, quấn quanh 'phản ứng liên lạc' và chỉ hiển thị nó nếu có một sự thay đổi trong tiểu bang. Để đơn giản hóa câu hỏi, tôi đã sử dụng phương thức shouldCompoenentUpdate()
để luôn trả về false.React shouldComponentUpdate() = false không dừng tái render
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;
gì xảy ra là nó luôn luôn rerenders, whish không nên xảy ra.
Bất kỳ ai cũng có ý tưởng tại sao điều đó lại xảy ra?
thêm console.log vào 'componentDidMount',' componentWillUpdate' và 'componentDidUpdate'see cái nào trong số chúng được kích hoạt. Nếu thành phần này chưa được kết nối và cập nhật lạiComponentUpdate sẽ không hoạt động – bennygenel