Hướng dẫn ReactJS ReactJS tutorial (p5) Bài 5: ReactJS Props Overview

6 180 5
Hướng dẫn ReactJS   ReactJS tutorial (p5) Bài 5: ReactJS  Props Overview

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

Thông tin tài liệu

Trong ReactJs ngoài state ra còn 1 hình thức lưu giữ data nữa đó là props, vậy props khác state như thế nào? Hiểu đơn giản là state thuộc về component, bạn có thể update, chỉnh sửa state, còn props cũng lưu dữ liệu như state nhưng được nhận từ component cha truyền xuống, bạn không thể chỉnh sửa trực tiếp props mà phải thay đổi từ cha nó. Bạn xem ví dụ sau để hiểu rõ hơn:

... return ( {this .props. headerProp} {this .props. contentProp} ); } } App.defaultProps = { headerProp: "Header from props ", contentProp:"Content from props " } export default... document.getElementById('app')); State and Props Ví dụ hướng dẫn bạn cách sử dụng state props với Chúng ta khởi tạo state component cha chuyền xuống components thông qua props App.js import React from 'react';... 'react'; class App extends React.Component { constructor (props) { super (props) ; this.state = { header: "Header from props ", content: "Content from props " } } render() { return (

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

Từ khóa liên quan

Mục lục

  • Bài 5: ReactJS - Props Overview

    • Default Props

    • State and Props

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

Tài liệu liên quan