Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate "AJAX and APIs" into Russian #30

Merged
merged 3 commits into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions content/docs/faq-ajax.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
---
id: faq-ajax
title: AJAX and APIs
title: AJAX и API, обращение к серверу
avevlad marked this conversation as resolved.
Show resolved Hide resolved
permalink: docs/faq-ajax.html
layout: docs
category: FAQ
---

### How can I make an AJAX call? {#how-can-i-make-an-ajax-call}
### Как выполнить AJAX-запрос к серверу? {#how-can-i-make-an-ajax-call}

You can use any AJAX library you like with React. Some popular ones are [Axios](https://github.com/axios/axios), [jQuery AJAX](https://api.jquery.com/jQuery.ajax/), and the browser built-in [window.fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
Вы можете использовать встроенный в браузер метод [window.fetch](https://learn.javascript.ru/fetch) или любую AJAX-библиотеку, например [Axios](https://github.com/axios/axios) или [jQuery AJAX](https://api.jquery.com/jQuery.ajax/).

### Where in the component lifecycle should I make an AJAX call? {#where-in-the-component-lifecycle-should-i-make-an-ajax-call}
### Где в жизненном цикле компонента я могу сделать AJAX-запрос? {#where-in-the-component-lifecycle-should-i-make-an-ajax-call}
avevlad marked this conversation as resolved.
Show resolved Hide resolved

You should populate data with AJAX calls in the [`componentDidMount`](/docs/react-component.html#mounting) lifecycle method. This is so you can use `setState` to update your component when the data is retrieved.
Вы можете сделать AJAX-запрос в [`componentDidMount`](/docs/react-component.html#mounting). Когда вы получите данные, вызовите `setState`, чтобы передать их компоненту.

### Example: Using AJAX results to set local state {#example-using-ajax-results-to-set-local-state}
### Пример: Установка внутреннего состояния из результатов AJAX-запроса {#example-using-ajax-results-to-set-local-state}
avevlad marked this conversation as resolved.
Show resolved Hide resolved

The component below demonstrates how to make an AJAX call in `componentDidMount` to populate local component state.
Компонент ниже показывает, как в `componentDidMount` задать внутреннее состояние из результата AJAX-запроса.

The example API returns a JSON object like this:
Допустим, наш API возвращает следующий JSON-объект:
avevlad marked this conversation as resolved.
Show resolved Hide resolved

```
{
Expand Down Expand Up @@ -50,9 +50,8 @@ class MyComponent extends React.Component {
items: result.items
});
},
// Note: it's important to handle errors here
// instead of a catch() block so that we don't swallow
// exceptions from actual bugs in components.
// Примечание: важно обрабатывать ошибки именно здесь, а не в блоке catch(),
// чтобы не перехватывать исключения из ошибок в самих компонентах.
(error) => {
this.setState({
isLoaded: true,
Expand All @@ -65,9 +64,9 @@ class MyComponent extends React.Component {
render() {
const { error, isLoaded, items } = this.state;
if (error) {
return <div>Error: {error.message}</div>;
return <div>Ошибка: {error.message}</div>;
} else if (!isLoaded) {
return <div>Loading...</div>;
return <div>Загрузка...</div>;
} else {
return (
<ul>
Expand Down
2 changes: 1 addition & 1 deletion content/docs/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
- title: FAQ
items:
- id: faq-ajax
title: AJAX and APIs
title: AJAX и API, обращение к серверу
- id: faq-build
title: Babel, JSX, and Build Steps
- id: faq-functions
Expand Down