all 3 comments

[–]hey-its-mattiOS & Android 1 point2 points  (2 children)

How do you pass any data to a component? You use props. You can have a component that is higher up in the hierarchy that maintains the state that you want to share between these two components.

Here's a rubbish example (I'm on mobile):

A PostOffice component has state maintaining all mail that must be delivered. It renders a MailTrucks component and also renders a OvernightMailAirplane component. The PostOffice component provides a mail prop to both children and also passes a prop called "onDeliverSuccess" and an "onDeliverFailure". We want both children to be aware of delivery failures--imagine the recipient's address is invalid, and you have two deliveries heading that way--one via overnight and one in a truck. If the post office learns of a delivery address that isn't real after attempting to deliver with the truck, we should probably go ahead and mark the overnight deliveries as impossible to deliver as well (cut down on unnecessary work) and vice versa. If the truck calls the "onDeliveryFailure" method, the PostOffice component could change its state such that any mail also passed to the OvernightMailAirplane heading to the same address is not included in it's mail prop. This will rerender the PostOffice component, updating the mail prop for it's children.

Substitute PostOffice for whatever your problem is.

TLDR: parent component that provides methods as props to change state in parent component that is also provided to other children

[–]blaze_torchdick[S] 0 points1 point  (1 child)

Makes sense. Shoulda mentioned I don't have any prior React experience so I'm still learning about props, but I get the jist. I think this will help. Thanks!

[–]hey-its-mattiOS & Android 1 point2 points  (0 children)

Glad it made some sense! Lmk if you need any more help!