Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Translate Components and Props page #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lofgrenfredrik
Copy link
Contributor

First draft of the Components and Props page.

@netlify
Copy link

netlify bot commented Aug 19, 2019

Deploy preview for sv-reactjs ready!

Built with commit 767288b

https://deploy-preview-10--sv-reactjs.netlify.com

@tesseralis tesseralis mentioned this pull request Dec 17, 2019
88 tasks

## Function and Class Components {#function-and-class-components}
## Funktion och klasskomponenter {#function-and-class-components}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say this is more fitting as Funktion- och klasskomponenter, see https://sv.wikipedia.org/wiki/Berg-_och_dalbana

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rloqvist Fixing. 👍

}
```

This function is a valid React component because it accepts a single "props" (which stands for properties) object argument with data and returns a React element. We call such components "function components" because they are literally JavaScript functions.
Denna funktion är en giltig Reakt-komponent eftersom den accepterar en enda "props" (som står för properties) objektargument med data och returnerar ett React-element. Vi kallar sådana komponenter "funktionskomponenter" eftersom de bokstavligen är JavaScript-funktioner.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reakt -> React

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rloqvist Fixing. 👍

}
}
```

The above two components are equivalent from React's point of view.
De två ovannämnda komponenterna är identiska ur Reacts synvinkel.

Classes have some additional features that we will discuss in the [next sections](/docs/state-and-lifecycle.html). Until then, we will use function components for their conciseness.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to remove this line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rloqvist Fixing. 👍


Classes have some additional features that we will discuss in the [next sections](/docs/state-and-lifecycle.html). Until then, we will use function components for their conciseness.

## Rendering a Component {#rendering-a-component}
Klasser har några ytterligare funktioner, som vi kommer att diskutera i [nästa avsnitt](/docs/state-and-lifecycle.html). Fram till dess kommer vi att använda för funktionskomponenter för deras tydlighet.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next sections are plural and therefore I think senare avsnitt would be a better fit here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rloqvist Fixing. 👍

3. Our `Welcome` component returns a `<h1>Hello, Sara</h1>` element as the result.
4. React DOM efficiently updates the DOM to match `<h1>Hello, Sara</h1>`.
1. Vi kallar `ReactDOM.render()` med React-elementet `<Welcome name="Sarah" />`.
2. React anropar `Welcome` komponenten med `{name: 'Sara'}` som dess "props".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"props" doesn't need quotes here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rloqvist Fixing. 👍


This component can be tricky to change because of all the nesting, and it is also hard to reuse individual parts of it. Let's extract a few components from it.

First, we will extract `Avatar`:
Denna komponent kan vara svår att ändra på grund av all nestling, det är också svårt att återanvända enskilda delar av den. Låt oss extrahera några komponenter från det.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mix of den and det

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing. 👍

@@ -173,9 +180,11 @@ function Avatar(props) {

The `Avatar` doesn't need to know that it is being rendered inside a `Comment`. This is why we have given its prop a more generic name: `user` rather than `author`.

We recommend naming props from the component's own point of view rather than the context in which it is being used.
`Avatar` behöver inte veta att den renderas i en `Comment`-komponent. Därför har vi gett dess Props ett mer generiskt namn: `user` istaället för `author`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

istaället -> istället

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing. 👍

We recommend naming props from the component's own point of view rather than the context in which it is being used.
`Avatar` behöver inte veta att den renderas i en `Comment`-komponent. Därför har vi gett dess Props ett mer generiskt namn: `user` istaället för `author`.

Vi rekommenderar att namnge Props från komponentens egen perspektiv snarare än i det sammanhang där den används.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lowercase the Props

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing. 👍


Whether you declare a component [as a function or a class](#function-and-class-components), it must never modify its own props. Consider this `sum` function:
Oavsett om du deklarerar en komponent [som en funktion eller en klass](#function-and-class-components), får den aldrig ändra sina egna Props. Ta denna `sum` funktion:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lowercase the Props

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing. 👍


```js
function sum(a, b) {
return a + b;
}
```

Such functions are called ["pure"](https://en.wikipedia.org/wiki/Pure_function) because they do not attempt to change their inputs, and always return the same result for the same inputs.
Sådana funktioner kallas ["ren"](https://en.wikipedia.org/wiki/Pure_function) eftersom de inte ändrar sina inputs och alltid returnerar samma resultat för samma inputs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plural and singular mix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say Sådana funktioner kallas för ["rena"] as a more proper translation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing. 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants