React Context API
旧版本的 context API 的 shouldComponentUpdate 问题
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class CComponent extends Component {
static contextTypes = {
color: PropTypes.string
}
render() {
return (
<span>{this.context.color}</span>
);
}
}
class MComponent extends Component {
shouldComponentUpdate() {
return false;
}
render() {
return (
<CComponent />
);
}
}
class Root extends Component {
static childContextTypes = {
color: PropTypes.string
}
getChildContext() {
return {
color: 'red',
}
}
render() {
return (
<MComponent />
);
}
}旧版本 Context API Key 冲突
新版本 Context API 的使用
使用新版本 Context API 取代 Redux?
新版 Context API 的其它问题
最后更新于