diff --git a/content/docs/nav.yml b/content/docs/nav.yml index ce5219f92..a2f0a67ef 100644 --- a/content/docs/nav.yml +++ b/content/docs/nav.yml @@ -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 diff --git a/content/docs/react-without-jsx.md b/content/docs/react-without-jsx.md index 85cdba45f..0b3393861 100644 --- a/content/docs/react-without-jsx.md +++ b/content/docs/react-without-jsx.md @@ -1,19 +1,20 @@ --- 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 { render() { - return
Hello {this.props.toWhat}
; + return
Привет, {this.props.toWhat}
; } } @@ -23,12 +24,12 @@ ReactDOM.render( ); ``` -can be compiled to this code that does not use JSX: +Он может быть превращён в код без JSX: ```js class Hello extends React.Component { render() { - return React.createElement('div', null, `Hello ${this.props.toWhat}`); + return React.createElement('div', null, `Привет, ${this.props.toWhat}`); } } @@ -38,22 +39,21 @@ 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` или обычной функции в случае компонента без состояния. -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; ReactDOM.render( - e('div', null, 'Hello World'), + e('div', null, 'Привет, мир!'), document.getElementById('root') ); ``` -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), которые предлагают короткий синтаксис.