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

更新文档 #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions Ch04/props-state-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ app.js:
class Timer extends React.Component {
constructor(props) {
super(props);
// 與 ES5 React.createClass({}) 不同的是 component 內自定義的方法需要自行綁定 this context,或是使用 arrow function
this.tick = this.tick.bind(this);
// 初始 state,等於 ES5 中的 getInitialState
this.state = {
secondsElapsed: 0,
Expand All @@ -125,7 +123,7 @@ class Timer extends React.Component {
}
// componentDidMount 為 component 生命週期中階段 component 已插入節點的階段,通常一些非同步操作都會放置在這個階段。這便是每1秒鐘會去呼叫 tick 方法
componentDidMount() {
this.interval = setInterval(this.tick, 1000);
this.interval = setInterval(this.tick.bind(this), 1000);
}
// componentWillUnmount 為 component 生命週期中 component 即將移出插入的節點的階段。這邊移除了 setInterval 效力
componentWillUnmount() {
Expand Down