# Xử lý State

**Khởi tạo State**

**State** được khởi tạo ở trong constructor với cấu trúc là 1 object gồm nhiều đối tượng. Ở ví dụ bên dưới, tôi tạo ra một đối tượng state là **count** với giá trị khởi tạo là số với giá trị bằng 0.&#x20;

```
class AddReaction extends PureComponent {
    constructor(props) {
        super(props);
        this.state={
            count:0
        };
    };
    
    updateCount=(newCount)=>{
        this.setState({count:newCount});
    };
    
    render(){
        return(
            <ChildComponent count={this.updateCount}/>
        )
    }
}
```

> * state: định nghĩa tên của state nó có thể là đơn giá trị hoặc object,.. (là tham số của useState)
> * setState: là function dùng cho việc update state


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://haonm.gitbook.io/react-the-complete-guide/understanding-the-base-features-and-syntax/manipulating-the-state-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
