Answer the question
In order to leave comments, you need to log in
How to forward the data inside the context?
Tell me pliz, I call the this.props.children function, react components are transferred to it (I don’t need them), how to make sure that the data is transferred there, i.e. context.data
<Provider value={{ data: [1, 2, 3333] }}>
<User>
{data => {
return <div>{data}</div>;
}}
</User>
</Provider>
class Header extends Component {
render() {
return (
<div>{this.props.children(<Consumer>{context => context.data}</Consumer>)}</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
The meaning of the context is that the data is available at any level of nesting, so there is no need to pass the data explicitly.
I use HOC to conveniently pass data from context to components: https://jsfiddle.net/n5u2wwjg/206004/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question