Skip to content

Commit 423d437

Browse files
committed
translate context
1 parent 1a83151 commit 423d437

9 files changed

+100
-105
lines changed

content/docs/context.md

+69-72
Large diffs are not rendered by default.

examples/context/motivation-problem.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ class App extends React.Component {
66

77
function Toolbar(props) {
88
// highlight-range{1-4,7}
9-
// The Toolbar component must take an extra "theme" prop
10-
// and pass it to the ThemedButton. This can become painful
11-
// if every single button in the app needs to know the theme
12-
// because it would have to be passed through all components.
9+
// Toolbar 컴포넌트는 ThemedButton에게 보내주기 위해
10+
// 불필요한 테마 prop를 받고 있습니다.
11+
// 앱 안의 모든 버튼이 테마를 알아야 한다면
12+
// 이 정보를 일일히 넘기는 과정은 매우 곤혹스러울 수 있습니다.
1313
return (
1414
<div>
1515
<ThemedButton theme={props.theme} />

examples/context/motivation-solution.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// highlight-range{1-4}
2-
// Context lets us pass a value deep into the component tree
3-
// without explicitly threading it through every component.
4-
// Create a context for the current theme (with "light" as the default).
2+
// context를 사용하면 모든 컴포넌트를 일일히 통하지 않고도
3+
// 원하는 값을 컴포넌트 트리 깊숙한 곳까지 보낼 수 있습니다.
4+
// 라이트(light)를 기본값으로 하는 테마 context를 만들어 봅시다.
55
const ThemeContext = React.createContext('light');
66

77
class App extends React.Component {
88
render() {
99
// highlight-range{1-3,5}
10-
// Use a Provider to pass the current theme to the tree below.
11-
// Any component can read it, no matter how deep it is.
12-
// In this example, we're passing "dark" as the current value.
10+
// Provider를 이용해 하위 트리에 테마 값을 보내줍니다.
11+
// 아무리 깊숙히 있어도, 모든 컴포넌트가 이 값을 읽을 수 있습니다.
12+
// 아래 예시에서는 다크(dark)를 현재 선택된 테마 값으로 보내고 있습니다.
1313
return (
1414
<ThemeContext.Provider value="dark">
1515
<Toolbar />
@@ -18,9 +18,8 @@ class App extends React.Component {
1818
}
1919
}
2020

21-
// highlight-range{1,2}
22-
// A component in the middle doesn't have to
23-
// pass the theme down explicitly anymore.
21+
// highlight-next-line
22+
// 이젠 중간에 있는 컴포넌트가 일일히 테마를 넘겨줄 필요가 없습니다.
2423
function Toolbar(props) {
2524
return (
2625
<div>
@@ -31,9 +30,9 @@ function Toolbar(props) {
3130

3231
class ThemedButton extends React.Component {
3332
// highlight-range{1-3,6}
34-
// Assign a contextType to read the current theme context.
35-
// React will find the closest theme Provider above and use its value.
36-
// In this example, the current theme is "dark".
33+
// 현재 선택된 테마 값을 읽기 위해 contextType을 지정합니다.
34+
// React는 가장 가까이 있는 테마 Provider를 찾아 그 값을 사용할 것입니다.
35+
// 이 예시에서 현재 선택된 테마는 다크입니다.
3736
static contextType = ThemeContext;
3837
render() {
3938
return <Button theme={this.context} />;

examples/context/multiple-contexts.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Theme context, default to light theme
1+
// 기본값이 light인 ThemeContext
22
const ThemeContext = React.createContext('light');
33

4-
// Signed-in user context
4+
// 로그인한 유저 정보를 담는 UserContext
55
const UserContext = React.createContext({
66
name: 'Guest',
77
});
@@ -10,7 +10,7 @@ class App extends React.Component {
1010
render() {
1111
const {signedInUser, theme} = this.props;
1212

13-
// App component that provides initial context values
13+
// context 초기값을 제공하는 App 컴포넌트
1414
// highlight-range{2-3,5-6}
1515
return (
1616
<ThemeContext.Provider value={theme}>
@@ -31,7 +31,7 @@ function Layout() {
3131
);
3232
}
3333

34-
// A component may consume multiple contexts
34+
// 여러 context의 값을 받는 컴포넌트
3535
function Content() {
3636
// highlight-range{2-10}
3737
return (

examples/context/theme-detailed-app.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {ThemeContext, themes} from './theme-context';
22
import ThemedButton from './themed-button';
33

4-
// An intermediate component that uses the ThemedButton
4+
// ThemedButton를 사용하는 중간에 있는 컴포넌트
55
function Toolbar(props) {
66
return (
77
<ThemedButton onClick={props.changeTheme}>
@@ -28,10 +28,9 @@ class App extends React.Component {
2828
}
2929

3030
render() {
31-
//highlight-range{1-3}
32-
// The ThemedButton button inside the ThemeProvider
33-
// uses the theme from state while the one outside uses
34-
// the default dark theme
31+
//highlight-range{1-2}
32+
// ThemeProvider 안에 있는 ThemedButton은 state로부터 theme 값을 읽지만
33+
// Provider 밖에 있는 ThemedButton는 기본값인 dark를 사용합니다.
3534
//highlight-range{3-5,7}
3635
return (
3736
<Page>

examples/context/theme-detailed-theme-context.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ export const themes = {
1111

1212
// highlight-range{1-3}
1313
export const ThemeContext = React.createContext(
14-
themes.dark // default value
14+
themes.dark // 기본값
1515
);

examples/context/updating-nested-context-app.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class App extends React.Component {
1515
};
1616

1717
// highlight-range{1-2,5}
18-
// State also contains the updater function so it will
19-
// be passed down into the context provider
18+
// state에 업데이트 메서드도 포함되어있으므로
19+
// 이 또한 context Provider를 통해 전달될것입니다.
2020
this.state = {
2121
theme: themes.light,
2222
toggleTheme: this.toggleTheme,
@@ -25,7 +25,7 @@ class App extends React.Component {
2525

2626
render() {
2727
// highlight-range{1,3}
28-
// The entire state is passed to the provider
28+
// Provider에 state 전체를 넘겨줍니다.
2929
return (
3030
<ThemeContext.Provider value={this.state}>
3131
<Content />

examples/context/updating-nested-context-context.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Make sure the shape of the default value passed to
2-
// createContext matches the shape that the consumers expect!
1+
// createContext에 보내는 기본값의 모양을
2+
// 하위 컴포넌트가 받고 있는 매개변수 모양과 동일하게 만드는 것 잊지마세요!
33
// highlight-range{2-3}
44
export const ThemeContext = React.createContext({
55
theme: themes.dark,

examples/context/updating-nested-context-theme-toggler-button.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {ThemeContext} from './theme-context';
22

33
function ThemeTogglerButton() {
44
// highlight-range{1-2,5}
5-
// The Theme Toggler Button receives not only the theme
6-
// but also a toggleTheme function from the context
5+
// ThemeTogglerButton는 context로부터
6+
// theme 값과 함께 toggleTheme 매서드도 받고 있습니다.
77
return (
88
<ThemeContext.Consumer>
99
{({theme, toggleTheme}) => (

0 commit comments

Comments
 (0)