Hướng dẫn ReactJS ReactJS tutorial (p7) Bài 7: ReactJS Tìm hiểu về Component Life Cycle

4 195 3
Hướng dẫn ReactJS   ReactJS tutorial (p7)  Bài 7: ReactJS  Tìm hiểu về Component Life Cycle

Đang tải... (xem toàn văn)

Thông tin tài liệu

Lifecycle Methods • componentWillMount đây là method sẽ được thực thi trước khi 1 component được render trên cả server side và client side. • componentDidMount method này được thực thi khi 1 component được render trên client side. Đây là nơi các hàm AJAX requests, DOM or update state được thực thi. Method này cũng đucợ sử dụng để kết nối với các JS Framework khác và các function với delayed execution như setTimeout or setInterval. • componentWillReceiveProps sẽ được thực thi ngay khi thuộc tính props (tìm hiểu props là gì?) được update và trước khi component được render lại. Trong ví dụ dưới, ta sẽ sử dung method này vùng với setNewNumber để update state.

... React .Component { componentWillMount() { console.log( 'Component WILL MOUNT!') } componentDidMount() { console.log( 'Component DID MOUNT!') } componentWillReceiveProps(newProps) { console.log( 'Component. .. WILL RECIEVE PROPS!') } shouldComponentUpdate(newProps, newState) { return true; } componentWillUpdate(nextProps, nextState) { console.log( 'Component WILL UPDATE!'); } componentDidUpdate(prevProps,... UPDATE!'); } componentDidUpdate(prevProps, prevState) { console.log( 'Component DID UPDATE!') } componentWillUnmount() { console.log( 'Component WILL UNMOUNT!') } render() { return ( {this.props.myNumber}

Ngày đăng: 03/04/2018, 17:28

Từ khóa liên quan

Mục lục

  • Bài 7: ReactJS - Tìm hiểu về Component Life Cycle

    • Lifecycle Methods

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan