From 9589085b8cd057bbe9be2794e2b98695282b86a5 Mon Sep 17 00:00:00 2001 From: Leonardo Negreiros de Oliveira Date: Fri, 8 Feb 2019 17:51:10 -0300 Subject: [PATCH 1/2] translate-faq-functions-to-portuguese --- content/docs/faq-functions.md | 139 +++++++++++++++++----------------- 1 file changed, 70 insertions(+), 69 deletions(-) diff --git a/content/docs/faq-functions.md b/content/docs/faq-functions.md index 62067d39c..c888b44dc 100644 --- a/content/docs/faq-functions.md +++ b/content/docs/faq-functions.md @@ -1,26 +1,26 @@ --- id: faq-functions -title: Passing Functions to Components +title: Passando Funções para Componentes permalink: docs/faq-functions.html layout: docs category: FAQ --- -### How do I pass an event handler (like onClick) to a component? {#how-do-i-pass-an-event-handler-like-onclick-to-a-component} +### Como eu passo um manipulador de eventos (como onClick) para um componente? {#how-do-i-pass-an-event-handler-like-onclick-to-a-component} -Pass event handlers and other functions as props to child components: +Passando manipuladores de evento e outras funções como props para componentes filhos: ```jsx ; + return ; } } ``` -#### Class Properties (Stage 3 Proposal) {#class-properties-stage-3-proposal} +#### Propriedades de Classe (Stage 3 Proposal) {#class-properties-stage-3-proposal} ```jsx class Foo extends Component { - // Note: this syntax is experimental and not standardized yet. + // Nota: esta sintaxe é experimental e ainda não padronizada. handleClick = () => { - console.log('Click happened'); + console.log('Clicado'); } render() { - return ; + return ; } } ``` -#### Bind in Render {#bind-in-render} +#### Bind no Render {#bind-in-render} ```jsx class Foo extends Component { handleClick() { - console.log('Click happened'); + console.log('Clicado'); } render() { - return ; + return ; } } ``` ->**Note:** +>**Nota:** > ->Using `Function.prototype.bind` in render creates a new function each time the component renders, which may have performance implications (see below). +>Ao usar `Function.prototype.bind` no render, uma nova função é criada cada vez que o componente é renderizado, o que pode afetar a performance (veja abaixo). -#### Arrow Function in Render {#arrow-function-in-render} +#### Arrow Function no Render {#arrow-function-in-render} ```jsx class Foo extends Component { handleClick() { - console.log('Click happened'); + console.log('Clicado'); } render() { - return ; + return ; } } ``` ->**Note:** +>**Nota:** > ->Using an arrow function in render creates a new function each time the component renders, which may have performance implications (see below). +>Ao usar uma arrow function no render, uma nova função é criada cada vez que o componente é renderizado, o que pode afetar a performance (veja abaixo). -### Is it OK to use arrow functions in render methods? {#is-it-ok-to-use-arrow-functions-in-render-methods} +### Devemos usar arrow functions em métodos de render? {#is-it-ok-to-use-arrow-functions-in-render-methods} -Generally speaking, yes, it is OK, and it is often the easiest way to pass parameters to callback functions. +De um modo geral, sim, é certo. E muitas das vezes é a maneira mais fácil de enviar parâmetros para funções de callback. -If you do have performance issues, by all means, optimize! +Se você tiver problemas de performance, de qualquer jeito, otimize! -### Why is binding necessary at all? {#why-is-binding-necessary-at-all} +### Porque binding é necessário afinal? {#why-is-binding-necessary-at-all} -In JavaScript, these two code snippets are **not** equivalent: +Em JavaScript, estes dois code snippets **não** são equivalentes: ```js obj.method(); @@ -104,50 +104,50 @@ var method = obj.method; method(); ``` -Binding methods helps ensure that the second snippet works the same way as the first one. +Métodos de binding ajudam a garantir que o segundo snippet funcione da mesma maneira que o primeiro. -With React, typically you only need to bind the methods you *pass* to other components. For example, ` + // Errado: handleClick é chamado ao invés de ser passado como referência! + return } ``` -Instead, *pass the function itself* (without parens): +Em vez disso, *passe a própria função* (sem parenteses): ```jsx render() { - // Correct: handleClick is passed as a reference! - return + // Correto: handleClick é passado como referência! + return } ``` -### How do I pass a parameter to an event handler or callback? {#how-do-i-pass-a-parameter-to-an-event-handler-or-callback} +### Como eu passo um parâmetro para um manipulador de evento ou um callback? {#how-do-i-pass-a-parameter-to-an-event-handler-or-callback} -You can use an arrow function to wrap around an event handler and pass parameters: +Você pode usar uma arrow function para envolver um manipulador de eventos e passar parâmetros: ```jsx