# Props trong ReactJs

> Props là một tính năng trong React cho phép component cha truyền dữ liệu cho component con.

- URL: https://vietanhjs.com/props-trong-reactjs.html
- Chuyên mục: [ReactJS Cơ bản](https://vietanhjs.com/reactjs-co-ban)
- Tác giả: [Hoàng Văn Việt Anh](https://hoangvanvietanh.com/)
- Xuất bản: 2023-02-11T16:41:52+07:00

---

Props là một tính năng trong React cho phép component cha truyền dữ liệu cho component con.

Bạn có thể hiểu Props như một cách truyền tham số từ component cha đến component con.

Ví dụ:

```

import React from 'react';

// Stateless component
const WelcomeMessage = (props) => {
  return <h1>Hello, {props.name}!</h1>;
};

// Stateful component
class App extends React.Component {
  render() {
    return (
      <div>
        <WelcomeMessage name="Viet" />
        <WelcomeMessage name="Anh" />
      </div>
    );
  }
}

export default App;
```

Trong ví dụ trên, component `WelcomeMessage` là một Stateless Component và nhận một thuộc tính `name` từ component cha `App`.

Component `App` render hai component `WelcomeMessage` với hai giá trị khác nhau cho thuộc tính `name`.

Kết quả sẽ là hai dòng "Hello, Viet!" và "Hello, Anh!".
