You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 21, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: content/docs/reference-react-dom.md
+36-36
Original file line number
Diff line number
Diff line change
@@ -6,109 +6,109 @@ category: Reference
6
6
permalink: docs/react-dom.html
7
7
---
8
8
9
-
If you load React from a `<script>` tag, these top-level APIs are available on the `ReactDOM` global. If you use ES6 with npm, you can write `import ReactDOM from 'react-dom'`. If you use ES5 with npm, you can write`var ReactDOM = require('react-dom')`.
9
+
Si carregues React des d'una etiqueta `<script>`, aquestes APIs de nivell superior estan disponibles en el `ReactDOM` global. Si fas servir ES6 amb npm, pots escriure `import ReactDOM from 'react-dom'`. Si utilitzes ES5 amb npm, pots escriure`var ReactDOM = require('react-dom')`.
10
10
11
-
## Overview {#overview}
11
+
## Resum {#overview}
12
12
13
-
The `react-dom`package provides DOM-specific methods that can be used at the top level of your app and as an escape hatch to get outside of the React model if you need to. Most of your components should not need to use this module.
13
+
El paquet `react-dom`proporciona mètodes específics del DOM que pots fer servir al nivell superior de la teva aplicació i com a escotilla per sortir del model React si cal. La majoria dels components no han de fer servir aquest mòdul.
React supports all popular browsers, including Internet Explorer 9 and above, although [some polyfills are required](/docs/javascript-environment-requirements.html)for older browsers such as IE 9 and IE 10.
23
+
React és compatible amb tots els navegadors populars, incloent-hi Internet Explorer 9 i superiors, tot i que [fan falta alguns *polyfills*](/docs/javascript-environment-requirements.html)per als navegadors més antics com ara l'IE 9 i l'IE 10.
24
24
25
-
> Note
25
+
> Nota
26
26
>
27
-
> We don't support older browsers that don't support ES5 methods, but you may find that your apps do work in older browsers if polyfills such as[es5-shim and es5-sham](https://github.com/es-shims/es5-shim)are included in the page. You're on your own if you choose to take this path.
27
+
> No garantim la compatibilitat amb els navegadors més antics que no suporten els mètodes ES5, però és possible que les teves aplicacions funcionin en navegadors més antics si els *polyfills* com ara[es5-shim i es5-sham](https://github.com/es-shims/es5-shim)s'inclouen a la pàgina. Si decideixes prendre aquest camí recorda que és sota la teva responsabilitat.
28
28
29
29
* * *
30
30
31
-
## Reference {#reference}
31
+
## Referències {#reference}
32
32
33
33
### `render()` {#render}
34
34
35
35
```javascript
36
-
ReactDOM.render(element, container[, callback])
36
+
ReactDOM.render(element, callback[, callback])
37
37
```
38
38
39
-
Render a React element into the DOM in the supplied `container` and return a [reference](/docs/more-about-refs.html)to the component (or returns`null`for [stateless components](/docs/components-and-props.html#function-and-class-components)).
39
+
Renderitza un element React al DOM en el *callback* subministrat i retorna un [referència](/docs/more-about-refs.html)al component (o retorna`null`per a [components sense estat](/docs/components-and-props.html#function-and-class-components)).
40
40
41
-
If the React element was previously rendered into `container`, this will perform an update on it and only mutate the DOM as necessary to reflect the latest React element.
41
+
Si l'element React s'ha renderitzat prèviament en el *callback*, en farà la seva actualització i només canviarà del DOM el que sigui necessari per reflectir l'últim element de React.
42
42
43
-
If the optional callback is provided, it will be executed after the component is rendered or updated.
43
+
Si es proporciona la *callback* opcional, s'executarà després que el component es renderitzi o s'actualitzi.
44
44
45
-
> Note:
45
+
> Nota:
46
46
>
47
-
> `ReactDOM.render()`controls the contents of the container node you pass in. Any existing DOM elements inside are replaced when first called. Later calls use React’s DOM diffing algorithm for efficient updates.
47
+
> `ReactDOM.render()`controla el contingut del node *callback* que s'hi passi. Qualsevol altre element DOM que sigui al seu interior es substitueix quan es crida per primer cop. Les crides posteriors fan servir l'algoritme de comparació del DOM de React per fer actualitzacions eficients.
48
48
>
49
-
> `ReactDOM.render()`does not modify the container node (only modifies the children of the container). It may be possible to insert a component to an existing DOM node without overwriting the existing children.
49
+
> `ReactDOM.render()`no modifica el node contenidor (només modifica els fills del contenidor). És possible inserir un component a un node DOM que ja existeix sense sobreescriure els fills existents.
50
50
>
51
-
> `ReactDOM.render()`currently returns a reference to the root `ReactComponent` instance. However, using this return value is legacy
52
-
> and should be avoided because future versions of React may render components asynchronously in some cases. If you need a reference to the root `ReactComponent` instance, the preferred solution is to attach a
53
-
> [callback ref](/docs/more-about-refs.html#the-ref-callback-attribute)to the root element.
51
+
> `ReactDOM.render()`actualment retorna una referència a la instància arrel `ReactComponent`. No obstant això, fer servir aquest valor de retorn és obsolet
52
+
> i s'ha d'evitar perquè les versions futures de React podran representar els components de forma asíncrona en alguns casos. Si necessites una referència a la instància arrel `ReactComponent`, la solució idònia és adjuntar una
> Using `ReactDOM.render()`to hydrate a server-rendered container is deprecated and will be removed in React 17. Use [`hydrate()`](#hydrate) instead.
55
+
> Fer servir `ReactDOM.render()`per hidratar un contenidor amb renderització des del servidor és obsolet i s'eliminarà a la versió 17 de React. Fes servir en el seu lloc [`hydrate()`](#hydrate).
56
56
57
57
* * *
58
58
59
59
### `hydrate()` {#hydrate}
60
60
61
61
```javascript
62
-
ReactDOM.hydrate(element, container[, callback])
62
+
ReactDOM.hydrate(element, callback[, callback])
63
63
```
64
64
65
-
Same as [`render()`](#render), but is used to hydrate a container whose HTML contents were rendered by [`ReactDOMServer`](/docs/react-dom-server.html). React will attempt to attach event listeners to the existing markup.
65
+
El mateix que [`render()`](#render), però s'utilitza per 'hidratar' un contenidor el contingut HTML del qual ha sigut renderitzat per [`ReactDOMServer`](/docs/react-dom-server.html). React provarà d'adjuntar detectors d'esdeveniments al marcador existent.
66
66
67
-
React expects that the rendered content is identical between the server and the client. It can patch up differences in text content, but you should treat mismatches as bugs and fix them. In development mode, React warns about mismatches during hydration. There are no guarantees that attribute differences will be patched up in case of mismatches. This is important for performance reasons because in most apps, mismatches are rare, and so validating all markup would be prohibitively expensive.
67
+
React espera que el contingut renderitzat sigui idèntic entre el servidor i el client. Pot corregir les diferències del contingut de text, però hauràs de tractar les discordances com errors i solucionar-les. En el mode de desenvolupament, React adverteix sobre les discordances durant la hidratació. No hi ha garantia que les diferències d'atribut siguin arreglades en cas de discordança. Això és important per raons de rendiment perquè a la majoria d'aplicacions són rares les discordances, i per tant, validar tots els marcadors tindria un cost massa alt.
68
68
69
-
If a single element's attribute or text content is unavoidably different between the server and the client (for example, a timestamp), you may silence the warning by adding `suppressHydrationWarning={true}`to the element. It only works one level deep, and is intended to be an escape hatch. Don't overuse it. Unless it's text content, React still won't attempt to patch it up, so it may remain inconsistent until future updates.
69
+
Si l'atribut d'un sol element o el contingut del text és inevitablement diferent entre el servidor i el client (per exemple, una marca de temps), pots silenciar l'avís afegint `suppressHydrationWarning={true}`a l'element. Només funciona amb un nivell de profunditat, i està destinat a ser una via de escapatòria. No n'abusis. Tret que sigui contingut de text, React no intentarà corregir-ho, de manera que pot ser que no sigui coherent fins a futures actualitzacions.
70
70
71
-
If you intentionally need to render something different on the server and the client, you can do a two-pass rendering. Components that render something different on the client can read a state variable like `this.state.isClient`, which you can set to `true`in `componentDidMount()`. This way the initial render pass will render the same content as the server, avoiding mismatches, but an additional pass will happen synchronously right after hydration. Note that this approach will make your components slower because they have to render twice, so use it with caution.
71
+
Si has de representar intencionadament quelcom diferent del servidor al client, pots fer-la en dos passos. Els components que renderitzen quelcom diferent del client poden llegir una variable d'estat com ara `this.state.isClient`, que pots establir a `true`dins de `componentDidMount()`. D'aquesta manera, en el pas inicial es renderitzarà el mateix contingut que en el servidor, evitant discordances i just després de la hidratació es renderitzarà síncronament un segon pas addicional. Tingues en compte que aquest enfocament farà que els teus components siguin més lents perquè s'han de renderitzar dues vegades, per tant fes-lo servir amb cura.
72
72
73
-
Remember to be mindful of user experience on slow connections. The JavaScript code may load significantly later than the initial HTML render, so if you render something different in the client-only pass, the transition can be jarring. However, if executed well, it may be beneficial to render a "shell" of the application on the server, and only show some of the extra widgets on the client. To learn how to do this without getting the markup mismatch issues, refer to the explanation in the previous paragraph.
73
+
Recorda tenir en compte l'experiència d'usuari en connexions lentes. El codi JavaScript es pot carregar força més tard que la renderització HTML inicial, de manera que si es renderitza alguna cosa diferent només en la part del client, la transició pot ser que grinyoli. Tot i això, si s'executa bé, pot ser beneficiós representar una shell de l'aplicació al servidor, i només mostrar alguns dels ginys addicionals en el client. Per a aprendre a fer-ho sense que hi hagi problemes de discordances, consulta l'explicació del paràgraf anterior.
Remove a mounted React component from the DOM and clean up its event handlers and state. If no component was mounted in the container, calling this function does nothing. Returns`true`if a component was unmounted and`false`if there was no component to unmount.
83
+
Elimina un component de React muntat des del DOM i neteja els seus gestors d’esdeveniments i estat. Si no s'ha muntat cap component al contenidor, la crida a aquesta funció no fa res. Retorna`true`si un component s'ha desmuntat i`false`si no hi ha cap component per desmuntar.
84
84
85
85
* * *
86
86
87
87
### `findDOMNode()` {#finddomnode}
88
88
89
-
> Note:
89
+
> Nota:
90
90
>
91
-
> `findDOMNode`is an escape hatch used to access the underlying DOM node. In most cases, use of this escape hatch is discouraged because it pierces the component abstraction. [It has been deprecated in `StrictMode`.](/docs/strict-mode.html#warning-about-deprecated-finddomnode-usage)
91
+
> `findDOMNode`és una escotilla de sortida feta servir per accedir al node DOM subjacent. En la majoria dels casos, l'ús d'aquesta sortida es desaconsella perquè trenca l'abstracció del component. [Ha quedat obsolet a l'`StrictMode`.](/docs/strict-mode.html#warning-about-deprecated-finddomnode-usage)
92
92
93
93
```javascript
94
94
ReactDOM.findDOMNode(component)
95
95
```
96
-
If this component has been mounted into the DOM, this returns the corresponding native browser DOM element. This method is useful for reading values out of the DOM, such as form field values and performing DOM measurements. **In most cases, you can attach a ref to the DOM node and avoid using `findDOMNode` at all.**
96
+
Si aquest component s'ha muntat en el DOM, retorna l'element corresponent del navegador natiu del DOM. Aquest mètode és útil per llegir els valors fora del DOM, com ara els valors de formulari i fer mesuraments de DOM. **En la majoria dels casos, pots adjuntar una referència al node DOM i així evitar utilitzar `find DOMNode`.**
97
97
98
-
When a component renders to `null`or`false`, `findDOMNode`returns`null`. When a component renders to a string, `findDOMNode`returns a text DOM node containing that value. As of React 16, a component may return a fragment with multiple children, in which case`findDOMNode`will return the DOM node corresponding to the first non-empty child.
98
+
Quan un component es renderitza a `null`o`false`, `findDOMNode`retorna`null`. Quan un component es renderitza a una cadena, `findDOMNode`retorna un node DOM que conté aquest valor. A partir de React 16, un component pot retornar un fragment amb diversos fills, en aquest cas`findDOMNode`retornarà el node DOM corresponent al primer fill que no estigui buit.
99
99
100
-
> Note:
100
+
> Nota:
101
101
>
102
-
> `findDOMNode`only works on mounted components (that is, components that have been placed in the DOM). If you try to call this on a component that has not been mounted yet (like calling `findDOMNode()`in `render()`on a component that has yet to be created) an exception will be thrown.
102
+
> `findDOMNode`només funciona amb components muntats (és a dir, components que s'han col·locat en el DOM). Si ho intentes amb un component que encara no s'ha muntat (com ara cridar `findDOMNode()`dins de `render()`en un component que encara no s'ha creat) es llançarà una excepció.
103
103
>
104
-
> `findDOMNode`cannot be used on function components.
104
+
> `findDOMNode`no es pot fer servir en components funcionals.
105
105
106
106
* * *
107
107
108
108
### `createPortal()` {#createportal}
109
109
110
110
```javascript
111
-
ReactDOM.createPortal(child, container)
111
+
ReactDOM.createPortal(child, callback)
112
112
```
113
113
114
-
Creates a portal. Portals provide a way to [render children into a DOM node that exists outside the hierarchy of the DOM component](/docs/portals.html).
114
+
Crea un portal. Els portals proporcionen una manera de [renderitzar els fills en un node DOM que existeix fora de la jerarquia del component DOM](/docs/portals.html).
0 commit comments