[react] childContextTypes是什么?它有什么用?

Posted 前端小歌谣

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[react] childContextTypes是什么?它有什么用?相关的知识,希望对你有一定的参考价值。

[react] childContextTypes是什么?它有什么用?

childContextTypes用来定义context数据类型,该api从16.3开始已被废弃

使用方式

class MessageList extends React.Component {
  getChildContext() {
    return {color: "purple"};
  }

  render() {
    return <div>MessageList</div>;
  }
}

MessageList.childContextTypes = {
  color: PropTypes.string
};

 个人简介

我是歌谣,欢迎和大家一起交流前后端知识。放弃很容易,
但坚持一定很酷。欢迎大家一起讨论



主目录

与歌谣一起通关前端面试题

以上是关于[react] childContextTypes是什么?它有什么用?的主要内容,如果未能解决你的问题,请参考以下文章