Reputation: 77
How pass props to component which is not a child component
//I want pass mainData to Component2
let mainData = [
{
text_plain: "Text1",
},
{
text_plain: "Text2",
},
];
function Component1 (props) {
return (
<div>
<Link to={`Component2 url`}>
</div>
)
}
I don't want to make the Сomponent2 a child, because i don't want rendering Component2 in Component1. How to solve this problem?
Upvotes: 1
Views: 74
Reputation: 250
For this you are going to want a global state management system. There are many out there, but I prefer context.
Context is a react hook and the documentation can be found here:
https://reactjs.org/docs/hooks-reference.html#usecontext
Upvotes: 1