Mục đích của tham số thứ 2 (là hàm callback) của setState là gì?

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

Hàm callback được gọi khi setState kết thúc và component được hiển thị. Vì setStatebất đồng bộ nên hàm callback được sử dụng để xử lý 1 logic nào đó sau khi setState kết thúc và component được hiển thị.

Lưu ý: Bạn nên sử dụng lifecycle (ví dụ, componentDidUpdate) thay sử dụng hàm callback này.

setState({name: 'PhongvanIT.com'}, () => console.log('The name has updated and component re-rendered'));
Câu hỏi tiếp theo: Làm sao để tạo các ref?
{{login.error}}