Skip to content
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

Translate react-dom/render section #561

Merged
merged 26 commits into from
Oct 30, 2022
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f5963a7
traducción al español de la sección react-dom/render
Oct 10, 2022
0767ac9
Merge branch 'main' into react-dom-render
carburo Oct 29, 2022
a8c0feb
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
fcc6504
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
783c7c1
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
e713c56
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
be57da7
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
14bc402
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
7b52a5d
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
c168b53
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
e87ba9a
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
b5498ad
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
e25bcbd
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
bc11331
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
b69cdb4
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
b0b548a
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
1ae46bf
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
7d9c9a1
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
f4ecb23
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
1e234a0
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
35e5bbc
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
55c6a61
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
1a34971
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
c45d66c
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
0688e25
Update beta/src/content/apis/react-dom/render.md
carburo Oct 29, 2022
93f2902
Update beta/src/content/apis/react-dom/render.md
fabianchoxD Oct 29, 2022
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
70 changes: 35 additions & 35 deletions beta/src/content/apis/react-dom/render.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ title: render

<Pitfall>

In React 18, `render` was replaced by [`createRoot`.](/apis/react-dom/client/createRoot) Using `render` in React 18 will warn that your app will behave as if it’s running React 17. Learn more [here.](https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-client-rendering-apis)
En React 18, `render` fue reemplazado por [`createRoot`.](/apis/react-dom/client/createRoot) Al usar `render` en React 18 se te advertirá que tu aplicación se comportará como si estuviera ejecutándose en React 17. Aprende mas [aquí.](https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-client-rendering-apis)

</Pitfall>


<Intro>

`render` renders a piece of [JSX](/learn/writing-markup-with-jsx) ("React node") into a browser DOM node.
`render` renderiza una pieza de [JSX](/learn/writing-markup-with-jsx) ("nodo de React") en un nodo del DOM del navegador.

```js
render(reactNode, domNode, callback?)
Expand All @@ -23,9 +23,9 @@ render(reactNode, domNode, callback?)

---

## Usage {/*usage*/}
## Uso {/*usage*/}

Call `render` to display a <CodeStep step={1}>React component</CodeStep> inside a <CodeStep step={2}>browser DOM node</CodeStep>.
Usa `render` para mostrar un <CodeStep step={1}>componente de React</CodeStep> dentro de un <CodeStep step={2}>nodo DOM del navegador</CodeStep>.

```js [[1, 4, "<App />"], [2, 4, "document.getElementById('root')"]]
import {render} from 'react-dom';
Expand All @@ -34,9 +34,9 @@ import App from './App.js';
render(<App />, document.getElementById('root'));
````

### Rendering the root component {/*rendering-the-root-component*/}
### Renderiza el componente raíz {/*rendering-the-root-component*/}

In apps fully built with React, **you will usually only do this once at startup**--to render the "root" component.
En aplicaciones totalmente construidas con React, **por lo general sólo realizarás esto una vez al inicio** --para renderizar el componente "raíz".

<Sandpack>

Expand All @@ -50,26 +50,26 @@ render(<App />, document.getElementById('root'));

```js App.js
export default function App() {
return <h1>Hello, world!</h1>;
return <h1>¡Hola, mundo!</h1>;
}
```

</Sandpack>

Usually you shouldn't need to call `render` again or to call it in more places. From this point on, React will be managing the DOM of your application. If you want to update the UI, your components can do this by [using state.](/apis/react/useState)
Generalmente no necesitas llamar a `render` de nuevo o llamarlo en otros lugares. En este punto, React manejará el DOM de tu aplicación. Si quieres actualizar la UI, tu componente puede hacerlo [con el uso de estado.](/apis/react/useState)

---

### Rendering multiple roots {/*rendering-multiple-roots*/}
### Renderizar múltiples raíces {/*rendering-multiple-roots*/}

If your page [isn't fully built with React](/learn/add-react-to-a-website), call `render` for each top-level piece of UI managed by React.
Si tu página [no está totalmente construida con React](/learn/add-react-to-a-website), llama a `render` por cada pieza de UI de nivel superior que esté administrada por React.

<Sandpack>

```html public/index.html
<nav id="navigation"></nav>
<main>
<p>This paragraph is not rendered by React (open index.html to verify).</p>
<p>Este párrafo no está renderizado por React (abre el archivo index.html para verificarlo).</p>
<section id="comments"></section>
</main>
```
Expand Down Expand Up @@ -112,8 +112,8 @@ export function Comments() {
return (
<>
<h2>Comments</h2>
<Comment text="Hello!" author="Sophie" />
<Comment text="How are you?" author="Sunil" />
<Comment text="¡Hola!" author="Sophie" />
<Comment text="¿Cómo estás?" author="Sunil" />
</>
);
}
Expand All @@ -132,13 +132,13 @@ nav ul li { display: inline-block; margin-right: 20px; }

</Sandpack>

You can destroy the rendered trees with [`unmountComponentAtNode()`.](/apis/react-dom/unmountComponentAtNode)
Puedes destruir los árboles renderizados con [`unmountComponentAtNode()`.](/apis/react-dom/unmountComponentAtNode)

---

### Updating the rendered tree {/*updating-the-rendered-tree*/}
### Actualizar el árbol renderizado {/*updating-the-rendered-tree*/}

You can call `render` more than once on the same DOM node. As long as the component tree structure matches up with what was previously rendered, React will [preserve the state.](/learn/preserving-and-resetting-state) Notice how you can type in the input, which means that the updates from repeated `render` calls every second in this example are not destructive:
Puedes llamar a `render` más de una vez en el mismo nodo del DOM. Siempre y cuando la estructura del árbol del componente coincida con lo renderizado previamente, React [preservará el estado.](/learn/preserving-and-resetting-state) Nota como puedes escribir en el input, lo que significa que las repetidas llamadas a `render` cada segundo en este ejemplo no son destructivas:

<Sandpack>

Expand All @@ -161,57 +161,57 @@ setInterval(() => {
export default function App({counter}) {
return (
<>
<h1>Hello, world! {counter}</h1>
<input placeholder="Type something here" />
<h1>¡Hola, mundo! {counter}</h1>
<input placeholder="Escribe algo aquí" />
</>
);
}
```

</Sandpack>

It is uncommon to call `render` multiple times. Usually, you'll [update state](/apis/react/useState) inside one of the components instead.
No es muy común llamar a `render` varias veces. Por lo general lo que debes hacer es [actualizar el estado](/apis/react/useState) dentro de uno de los componentes.

---

## Reference {/*reference*/}
## Referencia {/*reference*/}

### `render(reactNode, domNode, callback?)` {/*render*/}

Call `render` to display a React component inside a browser DOM element.
Utiliza `render` para mostrar un componente de React dentro de un elemento del DOM del navegador.

```js
const domNode = document.getElementById('root');
render(<App />, domNode);
```

React will display `<App />` in the `domNode`, and take over managing the DOM inside it.
React mostrará `<App />` en el `domNode`, y se encargará de gestionar el DOM dentro de él.

An app fully built with React will usually only have one `render` call with its root component. A page that uses "sprinkles" of React for parts of the page may have as many `render` calls as needed.
Una aplicación totalmente construida con React tendrá usualmente una sola llamada a `render` con su componente raíz. Una página que utiliza React para partes de la página puede tener tantas llamadas a `render` como sean necesarias.

[See examples above.](#usage)
[Mira los ejemplos anteriores.](#usage)

#### Parameters {/*parameters*/}
#### Parámetros {/*parameters*/}

* `reactNode`: A *React node* that you want to display. This will usually be a piece of JSX like `<App />`, but you can also pass a React element constructed with [`createElement()`](/apis/react/createElement), a string, a number, `null`, or `undefined`.
* `reactNode`: Un *nodo de React* que quieras mostrar. Por lo general se trata de una pieza de JSX como `<App />`, pero también puedes pasar un elemento de React construido con [`createElement()`](/apis/react/createElement), un _string_, un número, `null`, o `undefined`.

* `domNode`: A [DOM element.](https://developer.mozilla.org/en-US/docs/Web/API/Element) React will display the `reactNode` you pass inside this DOM element. From this moment, React will manage the DOM inside the `domNode` and update it when your React tree changes.
* `domNode`: Un [elemento del DOM.](https://developer.mozilla.org/en-US/docs/Web/API/Element) React mostrará el `reactNode` que pases dentro de este elemento del DOM. Desde este momento, React administrará el DOM dentro de `domNode` y lo actualizará cuando tu árbol de React cambie.

* **optional** `callback`: A function. If passed, React will call it after your component is placed into the DOM.
* `callback` **opcional**: Una función. Si se pasa, React la llamará luego de que tu componente sea colocado dentro del DOM.


#### Returns {/*returns*/}
#### Retorno {/*returns*/}

`render` usually returns `null`. However, if the `reactNode` you pass is a *class component*, then it will return an instance of that component.
`render` Por lo general retorna `null`. Sin embargo, si el `reactNode` que pasas es un *component de clase*, entonces retornará una instancia de ese componente.

#### Caveats {/*caveats*/}
#### Advertencias {/*caveats*/}

* In React 18, `render` was replaced by [`createRoot`.](/apis/react-dom/client/createRoot) Please use `createRoot` for React 18 and beyond.
* En React 18, `render` fue reemplazado por [`createRoot`.](/apis/react-dom/client/createRoot) Por favor usa `createRoot` para React 18 y versiones posteriores.

* The first time you call `render`, React will clear all the existing HTML content inside the `domNode` before rendering the React component into it. If your `domNode` contains HTML generated by React on the server or during the build, use [`hydrate()`](/apis/react-dom/hydrate) instead, which attaches the event handlers to the existing HTML.
* La primera vez que llamas a `render`, React limpiará todo el contenido HTML existente dentro del `domNode` antes de renderizar el componente de React dentro de este. Si tu `domNode` contiene HTML generado por React en el servidor o durante la compilación, usa en su lugar [`hydrate()`](/apis/react-dom/hydrate), ya que este adjunta los manejadores de eventos al HTML existente.

* If you call `render` on the same `domNode` more than once, React will update the DOM as necessary to reflect the latest JSX you passed. React will decide which parts of the DOM can be reused and which need to be recreated by ["matching it up"](/learn/preserving-and-resetting-state) with the previously rendered tree. Calling `render` on the same `domNode` again is similar to calling the [`set` function](/apis/react/useState#setstate) on the root component: React avoids unnecessary DOM updates.
* Si llamas a `render` en el mismo `domNode` más de una vez, React actualizará el DOM según sea necesario para reflejar el JSX más reciente que hayas pasado. React decidirá qué partes del DOM se pueden reutilizar y cuáles necesitan ser recreadas ["haciendo una comparación"](/learn/preserving-and-resetting-state) con el árbol previamente renderizado. Llamar de nuevo a `render` en el mismo `domNode` es similar a llamar a la función [`set` ](/apis/react/useState#setstate) en el componente raíz: React evita actualizaciones innecesarias del DOM.

* If your app is fully built with React, you'll likely have only one `render` call in your app. (If you use a framework, it might do this call for you.) When you want to render a piece of JSX in a different part of the DOM tree that isn't a child of your component (for example, a modal or a tooltip), use [`createPortal`](/apis/react-dom/createPortal) instead of `render`.
* Si tu aplicación está totalmente construida con React, es probable que tengas una sola llamada a `render` en tu aplicación. (Si usas un framework, puede que haga esta llamada por ti.) Cuando quieras renderizar un fragmento de JSX en un lugar diferente del árbol del DOM que no sea hijo de tu componente (por ejemplo, un modal o un _tooltip_), usa [`createPortal`](/apis/react-dom/createPortal) en lugar de `render`.

---