# 上下文

关于多个消费

const CustomerContext = React.createContext("2");

const Provide = (props) => {
  return (
    <CustomerContext.Provider value="2">
      {props.children}
    </CustomerContext.Provider>
  );
};

const withCustomer = (Component) => {
  return (props) => {
    const context = React.useContext(CustomerContext);
    return <Component {...props} some={context} />;
  };
};

如果是 class 组件的话

const withCustomer = (Component) => {
    return class extends React.Component {
        static contextType = CustomerContext;
        render() {
            <Component {...this.props} some={this.context}>
        }
    }
}

切记,高阶组价需要注意 forwardRef