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

docs: React.Component #75

Merged
merged 86 commits into from Sep 13, 2019
Merged

docs: React.Component #75

merged 86 commits into from Sep 13, 2019

Conversation

chloewlin
Copy link
Member

@chloewlin chloewlin commented Jun 30, 2019

6/30 - Set up branch for React.Component. This is a pretty long article (642 lines), I will commit often. Please feel free to review as I translate.

7/5 - Complete translation. Please see my notes and review.

  • Overview
    • The Component Lifecycle
      • Mounting
      • Updating
      • Unmounting
      • Error Handling
    • Other APIs
    • Class Properties
    • Instance Properties
  • Reference:
    • render()
    • constructor()
    • componentDidMount()
    • componentDidUpdate()
    • componentWillUnmount()
    • shouldComponentUpdate()
  • Rarely Used Life Cycle Methods
    • static getDerivedStateFromProps()
    • getSnapshotBeforeUpdate()
    • Error boundaries
    • static getDerivedStateFromError()
    • componentDidCatch()
    • Legacy Lifecycle Methods: UNSAFE_componentWillMount(), UNSAFE_componentWillReceiveProps(), UNSAFE_componentWillUpdate()
    • Other APIs: setState(), forceUpdate()
  • Class Properties:
    • defaultProps
    • displayName
    • props, state

@netlify
Copy link

netlify bot commented Jun 30, 2019

Deploy preview for zh-hant-reactjs-org ready!

Built with commit 8c649b5

https://deploy-preview-75--zh-hant-reactjs-org.netlify.com

Copy link
Member Author

@chloewlin chloewlin left a comment

Choose a reason for hiding this comment

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

I've commented on a few terms that I am not sure of. This doc is now ready for review. :)


Each component has several "lifecycle methods" that you can override to run code at particular times in the process. **You can use [this lifecycle diagram](http://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/) as a cheat sheet.** In the list below, commonly used lifecycle methods are marked as **bold**. The rest of them exist for relatively rare use cases.
每一個 component 都有數個 「生命週期方法」,你可以[覆蓋(override)](https://en.wikipedia.org/wiki/Method_overriding)這些方法,以便在開發過程中某些特定的時刻運行某些程式。 **你可以使用[這個生命週期表](http://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/)作為速查表。** 以下,常用的生命週期方法將會以粗體表達。其餘的生命週期方法則相對罕見。
Copy link
Member Author

Choose a reason for hiding this comment

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

I found this Wikipedia link helpful, so I added it. We can remove it if you think it's unnecessary.

content/docs/reference-react-component.md Outdated Show resolved Hide resolved

The `render()` function should be pure, meaning that it does not modify component state, it returns the same result each time it's invoked, and it does not directly interact with the browser.
`render()` function 應為純函數(pure function),這表示:它並不會改變 component 的 state,它在每次呼叫時都會返回同樣的結果,它並不會直接和瀏覽器有所互動。
Copy link
Member Author

Choose a reason for hiding this comment

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

I added 純函數(pure function) for clarity.


Avoid introducing any side-effects or subscriptions in the constructor. For those use cases, use `componentDidMount()` instead.
請避免在 constructor 中產生任何副作用或 subscription。如果你需要它們的話,請使用 `componentDidMount()`
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what subscription refers to here.


A snapshot value (or `null`) should be returned.
一個快照(snapshot)的值(或 `null`)應該被返回。
Copy link
Member Author

Choose a reason for hiding this comment

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

I can remove the English snapshot here if you think it's unnecessary.

>
> This lifecycle was previously named `componentWillUpdate`. That name will continue to work until version 17. Use the [`rename-unsafe-lifecycles` codemod](https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles) to automatically update your components.
> 這個生命週期方法先前的命名是 `componentWillUpdate`。這個命名直到第 17 版仍然能繼續運作。請使用[`重新命名不安全的生命週期方法` codemod](https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles) 來自動更新你的 component。
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure how to translate codemod.


The first argument is an `updater` function with the signature:
這個方法的第一個參數是一個帶有如下的 signature 的 `updater` function
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure how to translate function signature here.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe 形式 or 宣告?


```javascript
(state, props) => stateChange
```

`state` is a reference to the component state at the time the change is being applied. It should not be directly mutated. Instead, changes should be represented by building a new object based on the input from `state` and `props`. For instance, suppose we wanted to increment a value in state by `props.step`:
`state` 是當某個改變正在被應用時對 component state 的一個參考(reference)。它不應該直接被 mutate。相反的,任何改變都應該用一個基於 `state` `props` 的 input 所建立的新的 object 來表示。例如,假設我們想要使用 `props.step` 來增加 state 中的某個值的話:
Copy link
Member Author

Choose a reason for hiding this comment

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

I can remove reference here

Copy link
Member

Choose a reason for hiding this comment

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

I prefer to remove.


In particular, `this.props.children` is a special prop, typically defined by the child tags in the JSX expression rather than in the tag itself.
值得注意的是,`this.props.children` 是一個特別的 prop,通常在 JSX 表達式內的 child tag 內所定義,而不是其自身的 tag
Copy link
Member Author

Choose a reason for hiding this comment

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

How should I translate tag here?

Copy link
Member

Choose a reason for hiding this comment

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

Keeping original term haha.

chloewlin and others added 27 commits September 12, 2019 15:55
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
Co-Authored-By: Peng Jie <dean.leehom@gmail.com>
@chloewlin chloewlin merged commit ac2169c into reactjs:master Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants