# API

## Get data from external API

```
const url = "YOUR_API"
async function getArticles() {
  let result = await fetch(url).then(response => response.json());
  return result.articles;
}
```

From the sample code, we used async function to fetch data from API

## How to use it ?

```
constructor(props){
  super(props);
  this.state = { articles: [], isLoading: true };
}

componentDidMount() {
  this.fetchData();
 }

fetchData() {
  getArticles()
    .then(articles => this.setState({ articles, isLoading: false }))
    .catch(() => this.setState({error, isLoading: false }));
}
```

As you see, the function will be launch in componentDidMount. After that, we set those data into our 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://rnkit.gitbook.io/starter-kit/api.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.
