# Storing Data in React

* Data local to a component i.e. data which is not required to be shared across app or components:

1. Use component's local **state**
   * Use `this.state.onChange()` method to change the local state data and trigger a re-render of DOM
2. Use class level variable

   e.g. `public someLocalVar` or `private someLocalPrivateVar`

   Do not use class level variable for anything that you want to trigger re-rendeing of DOM

* Data to be used across application or across multiple components:
  1. Use Redux store and associate/connect your props variables with the global Redux store using the **connect** wrapper and a **mapStateToProps** function.


---

# 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://bharat-tiwari.gitbook.io/our-tech-journal/react/storing-data-in-react.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.
