Skip to content

Translated Context.md #93

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

Merged
merged 21 commits into from
Nov 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
143 changes: 74 additions & 69 deletions content/docs/context.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions examples/context/motivation-problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class App extends React.Component {
}

function Toolbar(props) {
// highlight-range{1-4,7}
// The Toolbar component must take an extra "theme" prop
// and pass it to the ThemedButton. This can become painful
// if every single button in the app needs to know the theme
// because it would have to be passed through all components.
// highlight-range{1-4,7}
// Diese Toolbar-Komponente muss eine extra "theme" Prop annehmen
// und an ThemedButton übergeben. Das kann sehr umständlich werden,
// wenn jeder einzelne Button in der App über das Theme bescheid
// wissen muss, weil es durch alle Komponenten durchgegeben werden muss.
return (
<div>
<ThemedButton theme={props.theme} />
Expand Down
22 changes: 11 additions & 11 deletions examples/context/motivation-solution.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// highlight-range{1-4}
// Context lets us pass a value deep into the component tree
// without explicitly threading it through every component.
// Create a context for the current theme (with "light" as the default).
// Context lasst uns einen Wert tief durch den Komponenten-Baum
// übergeben ohne ihn explizit durch jede Komponente durchzureichen.
// Erstelle einen Context für das aktuelle Theme (mit "light" als Standardwert).
const ThemeContext = React.createContext('light');

class App extends React.Component {
render() {
// highlight-range{1-3,5}
// Use a Provider to pass the current theme to the tree below.
// Any component can read it, no matter how deep it is.
// In this example, we're passing "dark" as the current value.
// Verwende einen Provider um das aktuelle Theme durch den Baum zu leiten.
// Jede Komponente kann es lesen, ganz egal wie tief sie liegt.
// In diesem Beispiel, übergeben wir "dark" als den aktuellen Wert.
return (
<ThemeContext.Provider value="dark">
<Toolbar />
Expand All @@ -19,8 +19,8 @@ class App extends React.Component {
}

// highlight-range{1,2}
// A component in the middle doesn't have to
// pass the theme down explicitly anymore.
// Eine Komponente in der Mitte braucht jetzt nicht
// mehr explizit das Theme weitergeben.
function Toolbar(props) {
return (
<div>
Expand All @@ -31,9 +31,9 @@ function Toolbar(props) {

class ThemedButton extends React.Component {
// highlight-range{1-3,6}
// Assign a contextType to read the current theme context.
// React will find the closest theme Provider above and use its value.
// In this example, the current theme is "dark".
// Weise einen contextType zu, um den aktuellen Theme Context zu lesen.
// React wird den nahestehensten Theme Provider darüber finden und dessen Wert lesen.
// In diesem Beispiel ist das aktuelle Theme "dark".
static contextType = ThemeContext;
render() {
return <Button theme={this.context} />;
Expand Down
8 changes: 4 additions & 4 deletions examples/context/multiple-contexts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Theme context, default to light theme
// Theme Context, Standardwert ist "light"
const ThemeContext = React.createContext('light');

// Signed-in user context
// Eingeloggter User-Context
const UserContext = React.createContext({
name: 'Guest',
});
Expand All @@ -10,7 +10,7 @@ class App extends React.Component {
render() {
const {signedInUser, theme} = this.props;

// App component that provides initial context values
// App Komponente die die initialen Context-Werte bereitstellt
// highlight-range{2-3,5-6}
return (
<ThemeContext.Provider value={theme}>
Expand All @@ -31,7 +31,7 @@ function Layout() {
);
}

// A component may consume multiple contexts
// Eine Komponente kann mehrere Contexte konsumieren
function Content() {
// highlight-range{2-10}
return (
Expand Down
8 changes: 4 additions & 4 deletions examples/context/theme-detailed-app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ThemeContext, themes} from './theme-context';
import ThemedButton from './themed-button';

// An intermediate component that uses the ThemedButton
// Eine Zwischen-Komponente die den ThemeButton verwendet
function Toolbar(props) {
return (
<ThemedButton onClick={props.changeTheme}>
Expand Down Expand Up @@ -29,9 +29,9 @@ class App extends React.Component {

render() {
//highlight-range{1-3}
// The ThemedButton button inside the ThemeProvider
// uses the theme from state while the one outside uses
// the default dark theme
// Der ThemeButton Button innerhalb von ThemeProvider verwendet
// das Theme des States, währenddessen der Button außerhalb
// das Default "dark" Theme verwendet
//highlight-range{3-5,7}
return (
<Page>
Expand Down
2 changes: 1 addition & 1 deletion examples/context/theme-detailed-theme-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export const themes = {

// highlight-range{1-3}
export const ThemeContext = React.createContext(
themes.dark // default value
themes.dark // Standardwert
);
6 changes: 3 additions & 3 deletions examples/context/updating-nested-context-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class App extends React.Component {
};

// highlight-range{1-2,5}
// State also contains the updater function so it will
// be passed down into the context provider
// State enthält auch die Update-Funktion, also wird
// es dem Context Provider überreicht.
this.state = {
theme: themes.light,
toggleTheme: this.toggleTheme,
Expand All @@ -25,7 +25,7 @@ class App extends React.Component {

render() {
// highlight-range{1,3}
// The entire state is passed to the provider
// Der gesamte State wird dem Provider überreicht.
return (
<ThemeContext.Provider value={this.state}>
<Content />
Expand Down
4 changes: 2 additions & 2 deletions examples/context/updating-nested-context-context.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Make sure the shape of the default value passed to
// createContext matches the shape that the consumers expect!
// Stelle sicher, dass die Form des Standardwertes, welcher an createContext
// überreicht wird mit der Form die der Konsument erwartet, übereinstimmt!
// highlight-range{2-3}
export const ThemeContext = React.createContext({
theme: themes.dark,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {ThemeContext} from './theme-context';

function ThemeTogglerButton() {
// highlight-range{1-2,5}
// The Theme Toggler Button receives not only the theme
// but also a toggleTheme function from the context
// Der Theme Toggler Button erhält nicht nur das Theme,
// sondern auch eine toggleTheme-Funktion von Context
return (
<ThemeContext.Consumer>
{({theme, toggleTheme}) => (
Expand Down