[react] contextType是什么?它有什么用?
定义当前组件要使用哪一个context
const MyContext = React.createContext(defaultValue);
class MyClass extends React.Component {
componentDidMount() {
let value = this.context;
/* perform a side-effect at mount using the value of MyContext */
}
}
MyClass.contextType = MyContext;
个人简介
我是歌谣,欢迎和大家一起交流前后端知识。放弃很容易,
但坚持一定很酷。欢迎大家一起讨论