|
1 | 1 | ---
|
2 | 2 | id: react-without-jsx
|
3 |
| -title: React Without JSX |
| 3 | +title: React sans JSX |
4 | 4 | permalink: docs/react-without-jsx.html
|
5 | 5 | ---
|
6 | 6 |
|
7 |
| -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. |
| 7 | +Vous n'êtes pas obligé·e d'employer JSX pour utiliser React. React sans JSX vous dispense de configurer votre environnement de travail pour gérer la compilation de votre code. |
8 | 8 |
|
9 |
| -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. |
| 9 | +Chaque élément JSX n'est rien de plus que du sucre syntaxique pour `React.createElement(component, props, ...children)`. Par conséquent, tout ce que vous pouvez faire avec JSX peut aussi être réalisé en Javascript brut. |
10 | 10 |
|
11 |
| -For example, this code written with JSX: |
| 11 | +Prenons par exemple ce code écrit avec JSX : |
12 | 12 |
|
13 | 13 | ```js
|
14 | 14 | class Hello extends React.Component {
|
15 | 15 | render() {
|
16 |
| - return <div>Hello {this.props.toWhat}</div>; |
| 16 | + return <div>Bonjour {this.props.toWhat}</div>; |
17 | 17 | }
|
18 | 18 | }
|
19 | 19 |
|
20 | 20 | ReactDOM.render(
|
21 |
| - <Hello toWhat="World" />, |
| 21 | + <Hello toWhat="monde" />, |
22 | 22 | document.getElementById('root')
|
23 | 23 | );
|
24 | 24 | ```
|
25 | 25 |
|
26 |
| -can be compiled to this code that does not use JSX: |
| 26 | +Il peut être compilé vers ce code qui n'utilise pas JSX : |
27 | 27 |
|
28 | 28 | ```js
|
29 | 29 | class Hello extends React.Component {
|
30 | 30 | render() {
|
31 |
| - return React.createElement('div', null, `Hello ${this.props.toWhat}`); |
| 31 | + return React.createElement('div', null, `Bonjour ${this.props.toWhat}`); |
32 | 32 | }
|
33 | 33 | }
|
34 | 34 |
|
35 | 35 | ReactDOM.render(
|
36 |
| - React.createElement(Hello, {toWhat: 'World'}, null), |
| 36 | + React.createElement(Hello, {toWhat: 'monde'}, null), |
37 | 37 | document.getElementById('root')
|
38 | 38 | );
|
39 | 39 | ```
|
40 | 40 |
|
41 |
| -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). |
| 41 | +Si vous voulez voir plus d'exemples de conversion de code JSX en JavaScript brut, vous pouvez essayer [le compilateur Babel en ligne](babel://jsx-simple-example). |
42 | 42 |
|
43 |
| -The component can either be provided as a string, or as a subclass of `React.Component`, or a plain function for stateless components. |
| 43 | +Le composant peut être soit une chaîne de caractères, soit une sous-classe de `React.Component`, soit une fonction simple pour les composants sans état. |
44 | 44 |
|
45 |
| -If you get tired of typing `React.createElement` so much, one common pattern is to assign a shorthand: |
| 45 | +Si vous n'avez pas envie de taper `React.createElement` à chaque fois, vous pouvez à la place créer un raccourci : |
46 | 46 |
|
47 | 47 | ```js
|
48 | 48 | const e = React.createElement;
|
49 | 49 |
|
50 | 50 | ReactDOM.render(
|
51 |
| - e('div', null, 'Hello World'), |
| 51 | + e('div', null, 'Bonjour, monde'), |
52 | 52 | document.getElementById('root')
|
53 | 53 | );
|
54 | 54 | ```
|
| 55 | +Si vous utilisez un tel raccourci pour `React.createElement`, utiliser React sans JSX devient presque aussi pratique. |
55 | 56 |
|
56 |
| -If you use this shorthand form for `React.createElement`, it can be almost as convenient to use React without JSX. |
57 |
| - |
58 |
| -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. |
59 |
| - |
| 57 | +Dans le même esprit, vous pouvez aller regarder des projets tels que [`react-hyperscript`](https://github.com/mlmorg/react-hyperscript) ou [`hyperscript-helpers`](https://github.com/ohanhi/hyperscript-helpers), qui proposent une syntaxe encore plus concise. |
0 commit comments