React源码分析第四节

context

跨级通信

childContextType :老的, React17废弃
createContext :React16之后

import React from 'react'
import PropTypes from 'prop-types'

const {Provider, Consumer} = React.createContext("default")

class Parent extends React.Component {
 state = {
  childContext:"123",
  newContext:"4567"
 }
 render() {
  return (
    <React.Fragment>
   )
 }
}

你可能感兴趣的:(前端,源码)