Skip to content
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

Translation for Hooks / useContext #878

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

Conversation

hellcattc
Copy link

No description provided.

Copy link
Collaborator

@titovmx titovmx left a comment

Choose a reason for hiding this comment

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

привет! отличная работа! оставил несколько комментариев, что думаете?

src/content/reference/react/useContext.md Show resolved Hide resolved

#### Returns {/*returns*/}
`useContext` возвращает значение контекста для вызывающего компонента. Оно определяется как `value`, переданное ближайшему `SomeContext.Provider` выше по дереву, чем вызывающий компонент. Если такого источника нет, то вернётся `defaultValue`, который вы передали в [`createContext`](/reference/react/createContext) для этого контекста. Возвращаемое значение всегда актуально. React автоматически повторно рендерит компоненты, которые считывают определённый контекст, при его изменении.
Copy link
Collaborator

@titovmx titovmx Jun 23, 2023

Choose a reason for hiding this comment

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

Suggested change
`useContext` возвращает значение контекста для вызывающего компонента. Оно определяется как `value`, переданное ближайшему `SomeContext.Provider` выше по дереву, чем вызывающий компонент. Если такого источника нет, то вернётся `defaultValue`, который вы передали в [`createContext`](/reference/react/createContext) для этого контекста. Возвращаемое значение всегда актуально. React автоматически повторно рендерит компоненты, которые считывают определённый контекст, при его изменении.
#### Возвращаемое значение {/*returns*/}
`useContext` возвращает значение контекста для вызывающего компонента. Оно определяется как `value`, переданное ближайшему `SomeContext.Provider` выше по дереву, чем вызывающий компонент. Если такого источника нет, то вернётся `defaultValue`, который вы передали в [`createContext`](/reference/react/createContext) для этого контекста. Возвращаемое значение всегда актуально. React автоматически повторно рендерит компоненты, которые считывают определённый контекст, когда он меняется.

Copy link
Author

Choose a reason for hiding this comment

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

С изменением в конце согласен, а вот "по дереву, ближайшему к вызывающему компоненту" не очень звучит, может, есть другие предложения?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Согласен, получилось не очень.
Может что-то вроде "React идёт вверх по дереву, берёт ближайший к вызывающему компоненту SomeContext.Provider и возвращает переданное ему value". Или оставить исходное - поправил коммент, если решите остановиться на том варианте, но мне показалось перечисление условий в таком виде тяжеловатым для восприятия.

Copy link
Author

Choose a reason for hiding this comment

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

Да, наверное лучше полностью структуру предложения перелопатить, норм вариант, нужно подумать еще

src/content/reference/react/useContext.md Outdated Show resolved Hide resolved
src/content/reference/react/useContext.md Outdated Show resolved Hide resolved
src/content/reference/react/useContext.md Outdated Show resolved Hide resolved
src/content/reference/react/useContext.md Outdated Show resolved Hide resolved
src/content/reference/react/useContext.md Outdated Show resolved Hide resolved
src/content/reference/react/useContext.md Outdated Show resolved Hide resolved
src/content/reference/react/useContext.md Outdated Show resolved Hide resolved
src/content/reference/react/useContext.md Outdated Show resolved Hide resolved
hellcattc and others added 2 commits June 24, 2023 19:43
Co-authored-by: Maxim <mtitov92@gmail.com>
Co-authored-by: Maxim <mtitov92@gmail.com>
hellcattc and others added 2 commits June 24, 2023 19:47
Co-authored-by: Maxim <mtitov92@gmail.com>
Co-authored-by: Maxim <mtitov92@gmail.com>
hellcattc and others added 4 commits June 24, 2023 19:53
Co-authored-by: Maxim <mtitov92@gmail.com>
Co-authored-by: Maxim <mtitov92@gmail.com>
Co-authored-by: Maxim <mtitov92@gmail.com>
Co-authored-by: Maxim <mtitov92@gmail.com>
Co-authored-by: Maxim <mtitov92@gmail.com>
* `useContext()` call in a component is not affected by providers returned from the *same* component. The corresponding `<Context.Provider>` **needs to be *above*** the component doing the `useContext()` call.
* React **automatically re-renders** all the children that use a particular context starting from the provider that receives a different `value`. The previous and the next values are compared with the [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) comparison. Skipping re-renders with [`memo`](/reference/react/memo) does not prevent the children receiving fresh context values.
* If your build system produces duplicates modules in the output (which can happen with symlinks), this can break context. Passing something via context only works if `SomeContext` that you use to provide context and `SomeContext` that you use to read it are ***exactly* the same object**, as determined by a `===` comparison.
* Вызов `useContext()` из компонента не будет затронут источниками, возвращёнными из *того же* компонента. Соответствующий `<Context.Provider>` **обязан быть *выше по дереву***, чем компонент, который вызывает `useContext()`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

пожалуйста убедитесь, что нет лишних переносов строк. чтобы не было проблем при ребейзе

Copy link
Author

Choose a reason for hiding this comment

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

все проверил, пофиксил то, что нашел

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

Successfully merging this pull request may close these issues.

None yet

3 participants