import React,{createContext} from 'react'; import ReactDOM from 'react-dom'; let {Provider, Consumer} = createContext(); //统一状态管理 class ProviderComponent extends React.Component{ state={ a:1, b:22 } changeDataA = (a) =>{ this.setState({a}) } render(){ return ( {this.props.children} ) } } class Child extends React.Component{ render(){ return (
{(data)=>

{JSON.stringify(data)}

}
) } } class App extends React.Component{ render(){ return (
) } } class App2 extends React.Component{ render(){ return (
{(data)=>

{data.state.a}

}
) } } ReactDOM.render( , document.getElementById('root'));