Fe-interview: [react] childContextTypes是什么?它有什么用?

Created on 18 Jul 2019  ·  1Comment  ·  Source: haizlin/fe-interview

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

react

Most helpful comment

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

使用方式

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

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

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

>All comments

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

使用方式

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

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

MessageList.childContextTypes = {
  color: PropTypes.string
};
Was this page helpful?
0 / 5 - 0 ratings