React có re-render tất cả các components và sub components mỗi khi setState được gọi không?

{{FormatNumbertoThousand(model.total_like)}} lượt thích
420 lượt xem
Reactjs senior

Mặc định là .

Có một phương thức boolean shouldComponentUpdate (object nextProps, object nextState), mỗi component có phương thức này và nó có trách nhiệm xác định "nên cập nhật component (chạy hàm render)?" mỗi khi bạn thay đổi state hoặc truyền các props mới từ component cha.

Bạn có thể viết triển khai phương thức shouldComponentUpdate của riêng mình cho component của bạn, nhưng mặc định luôn trả về true - nghĩa là luôn chạy lại hàm render.

{{login.error}}