麻烦大佬帮忙看解释下这段react的代码的作用,另外,这个global是哪里来的?
const appCtx = React.createContext();
const { Provider: AppProvider, Consumer: AppConsumer } = appCtx;
const withAppComponent = Component => props => (
<AppConsumer>
{global => {
let { global: propsGlobal, ecsRef, ...others } = props;
return (
<Component
{...others}
global={{ ...propsGlobal, ...global }}
></Component>
);
}}
</AppConsumer>
export class WrapAppComponent extends Component {
render() {
let { id, component, global: propsGlobal, ecsRef, ...others } = this.props;
return (
<AppConsumer>
{global =>
React.createElement(
component,
{
key: id,
ref: ecsRef,
...others,
global: { ...propsGlobal, ...global }
},
null
)
}
</AppConsumer>
);
}
}
);
这是createContext这个Api的写法
https://zh-hans.reactjs.org/d...