Skip to content

Translate context #79

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 7 commits into from
Apr 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
141 changes: 69 additions & 72 deletions content/docs/context.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/context/motivation-problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ 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.
// Toolbar 컴포넌트는 불필요한 테마 prop를 받아서
// ThemeButton에 전달해야 합니다.
// 앱 안의 모든 버튼이 테마를 알아야 한다면
// 이 정보를 일일이 넘기는 과정은 매우 곤혹스러울 수 있습니다.
return (
<div>
<ThemedButton theme={props.theme} />
Expand Down
23 changes: 11 additions & 12 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를 사용하면 모든 컴포넌트를 일일이 통하지 않고도
// 원하는 값을 컴포넌트 트리 깊숙한 곳까지 보낼 수 있습니다.
// light를 기본값으로 하는 테마 context를 만들어 봅시다.
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.
// Provider를 이용해 하위 트리에 테마 값을 보내줍니다.
// 아무리 깊숙히 있어도, 모든 컴포넌트가 이 값을 읽을 수 있습니다.
// 아래 예시에서는 dark를 현재 선택된 테마 값으로 보내고 있습니다.
return (
<ThemeContext.Provider value="dark">
<Toolbar />
Expand All @@ -18,9 +18,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.
// highlight-next-line
// 이젠 중간에 있는 컴포넌트가 일일이 테마를 넘겨줄 필요가 없습니다.
function Toolbar(props) {
return (
<div>
Expand All @@ -31,9 +30,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".
// 현재 선택된 테마 값을 읽기 위해 contextType을 지정합니다.
// React는 가장 가까이 있는 테마 Provider를 찾아 그 값을 사용할 것입니다.
// 이 예시에서 현재 선택된 테마는 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
// 기본값이 light인 ThemeContext
const ThemeContext = React.createContext('light');

// Signed-in user context
// 로그인한 유저 정보를 담는 UserContext
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
// context 초기값을 제공하는 App 컴포넌트
// 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
// 여러 context의 값을 받는 컴포넌트
function Content() {
// highlight-range{2-10}
return (
Expand Down
9 changes: 4 additions & 5 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
// ThemedButton를 사용하는 중간에 있는 컴포넌트
function Toolbar(props) {
return (
<ThemedButton onClick={props.changeTheme}>
Expand All @@ -28,10 +28,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
//highlight-range{1-2}
// ThemeProvider 안에 있는 ThemedButton은 state로부터 theme 값을 읽지만
// Provider 밖에 있는 ThemedButton는 기본값인 dark를 사용합니다.
//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 // 기본값
);
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에 업데이트 메서드도 포함되어있으므로
// 이 또한 context Provider를 통해 전달될것입니다.
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
// Provider에 state 전체를 넘겨줍니다.
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!
// createContext에 보내는 기본값의 모양을
// 하위 컴포넌트가 받고 있는 매개변수 모양과 동일하게 만드는 것 잊지마세요!
// 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
// ThemeTogglerButton는 context로부터
// theme 값과 함께 toggleTheme 매서드도 받고 있습니다.
return (
<ThemeContext.Consumer>
{({theme, toggleTheme}) => (
Expand Down