From 663f57a2eac66b41dd8fa83753ac823cfb865d53 Mon Sep 17 00:00:00 2001 From: avevlad Date: Sat, 9 Feb 2019 22:28:08 +0300 Subject: [PATCH 1/3] Translate "AJAX and APIs" into Russian --- content/docs/faq-ajax.md | 25 ++++++++++++------------- content/docs/nav.yml | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/content/docs/faq-ajax.md b/content/docs/faq-ajax.md index 102e1c07e..c2b8ae84f 100644 --- a/content/docs/faq-ajax.md +++ b/content/docs/faq-ajax.md @@ -1,24 +1,24 @@ --- id: faq-ajax -title: AJAX and APIs +title: Запрос к серверу, AJAX и APIs 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). +Используйте любую AJAX библиотеку, например [Axios](https://github.com/axios/axios) или [jQuery AJAX](https://api.jquery.com/jQuery.ajax/). А еще присмотритесь к встроенному в браузер методу [window.fetch](https://learn.javascript.ru/fetch). -### 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} -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. +В методе [`componentDidMount`](/docs/react-component.html#mounting). Сделайте AJAX запрос и используйте `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} -The component below demonstrates how to make an AJAX call in `componentDidMount` to populate local component state. +Компонент ниже демонстрирует как сделать AJAX запрос в `componentDidMount` для дальнейшего обновления внутреннего состояния. -The example API returns a JSON object like this: +Допустим, наш API возвращает следующий JSON-объект: ``` { @@ -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, @@ -65,9 +64,9 @@ class MyComponent extends React.Component { render() { const { error, isLoaded, items } = this.state; if (error) { - return
Error: {error.message}
; + return
Ошибка: {error.message}
; } else if (!isLoaded) { - return
Loading...
; + return
Загрузка...
; } else { return (