Skip to content

React без JSX #118

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

Merged
merged 9 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion content/docs/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
- id: react-without-es6
title: React Without ES6
- id: react-without-jsx
title: React Without JSX
title: React без JSX
- id: reconciliation
title: Reconciliation
- id: refs-and-the-dom
Expand Down
22 changes: 11 additions & 11 deletions content/docs/react-without-jsx.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
id: react-without-jsx
title: React Without JSX
title: React без JSX
permalink: docs/react-without-jsx.html
---

JSX is not a requirement for using React. Using React without JSX is especially convenient when you don't want to set up compilation in your build environment.
JSX не является обязательным при работе с React. Использование React без JSX особенно удобно, когда вы не хотите настраивать транспиляцию в процессе сборки.

Each JSX element is just syntactic sugar for calling `React.createElement(component, props, ...children)`. So, anything you can do with JSX can also be done with just plain JavaScript.
Каждый JSX элемент -- это просто синтаксический сахар для вызова `React.createElement(component, props, ...children)`. Так что всё, что вы можете сделать при помощи JSX, так же может быть сделано на чистом JavaScript.

Для примера -- этот код написаный на JSX:

For example, this code written with JSX:

```js
class Hello extends React.Component {
Expand All @@ -23,7 +24,7 @@ ReactDOM.render(
);
```

can be compiled to this code that does not use JSX:
может быть превращен в следующий код, который не использует JSX:

```js
class Hello extends React.Component {
Expand All @@ -38,11 +39,11 @@ ReactDOM.render(
);
```

If you're curious to see more examples of how JSX is converted to JavaScript, you can try out [the online Babel compiler](babel://jsx-simple-example).
Если вас интересуют другие примеры того, как JSX превращается в JavaScript, вы можете попробовать [онлайн транспилятор Babel](babel://jsx-simple-example).

The component can either be provided as a string, or as a subclass of `React.Component`, or a plain function for stateless components.
Компонент может быть представлен в виде строки, класса-наследника от `React.Component` или обычной функции для компонентa без состояния.

If you get tired of typing `React.createElement` so much, one common pattern is to assign a shorthand:
Если вас сильно утомляет печатать `React.createElement`, то типовым подходом является создание сокращения для этого:

```js
const e = React.createElement;
Expand All @@ -53,7 +54,6 @@ ReactDOM.render(
);
```

If you use this shorthand form for `React.createElement`, it can be almost as convenient to use React without JSX.

Alternatively, you can refer to community projects such as [`react-hyperscript`](https://github.com/mlmorg/react-hyperscript) and [`hyperscript-helpers`](https://github.com/ohanhi/hyperscript-helpers) which offer a terser syntax.
Если вы используете эту сокращенную форму для `React.createElement`, то использование React без JSX станет почти таким же удобным, как вы привыкли.

Кроме того, вы можете посмотреть на такие открытые проекты как [`react-hyperscript`](https://github.com/mlmorg/react-hyperscript) и [`hyperscript-helpers`](https://github.com/ohanhi/hyperscript-helpers), которые предлагают более краткий синтаксис.