react - context

Context-上下文

import React, { Component } from 'react';
import { Button } from 'antd'
const Them = React.createContext()

class Btn extends Component {
  // 1. 使用 `contextType`
  // static contextType = Them
  render() {
    // return 
    
    // 2. 使用 `Consumer` 类定义
    return (
      
        {
          value => {
            return 
          }
        }
      
    )
  }
}

class Toolbar extends Component {
  render() {
    return 
  }
}

class ContextSimple extends Component {
  constructor(props){
    super(props)
    this.state = {
      store: {
        type: 'default',
        name: '按钮2'
      }
    }
  }
  render() {
    return (
      
); } } export default ContextSimple;

你可能感兴趣的:(react.js,context)