Skip to Content
React学习手册
book

React学习手册

by Alex Banks, Eve Porcello
December 2017
Intermediate to advanced
329 pages
6h 9m
Chinese
China Electric Power Press Ltd.
Content preview from React学习手册
150
7
}
componentDidUpdate(prevProps) {
const { title, rating } = this.props
const status = (rating > prevProps.rating) ? 'better' : 'worse'
console.log(`${title} is getting ${status}`)
}
7
-
3
:使用shouldComponentUpdate方法每次只更新一个组件
更新生命周期方法
componentWillUpdate
componentDidUpdate
更新之前或者之后
DOM
交互的好地方。在接下来的示例中,更新过程将会被
componentWillUpdate
法中的一个警告提示框暂停:
componentWillMount() {
this.style = { backgroundColor: "#CCC" }
}
shouldComponentUpdate(nextProps) {
return this.props.rating !== nextProps.rating
}
componentWillUpdate(
nextProps
) {
const { title, rating } = this.props
this.style = null
组件扩展
151
this.refs.title.style.backgroundColor = "red"
this.refs.title.style.color ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

React快速上手开发

React快速上手开发

Stoyan Stefanov
流畅的Python

流畅的Python

Luciano Ramalho
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9787519814236