In order to achieve this communication i suggest that the child (CardSide Component) communicates with the Card Component via Events .
so when the user finish his operation on the card component an event is fired passing all the data to the parent let me show you an example for what i mean :
Card Component
class Card extends Component {
handleCompelete = data => {
//the data here are all the data entered from the child component
//do some sorting using table name
};
render() {
return <CardSide onCompelete={this.handleCompelete} />;
}
}
CardSide Component
class CardComponent extends Component {
render() {
return (
<div>
{/* data here reprensets what you need to transfer to parent component */}
<button onClick={() => this.props.onCompelete(data)} />
</div>
);
}
}
Edit
You cannot access the state of the child component as it is private to it.
Regarding to the props , you can access it but it is ReadOnly that is passed from the parent component but the child component cannot modify it .
Actually there is a way to access the component children (but i see it will complicate your code rather than simplifying it and i do not recommend this )
lets say that this is you app.js
class App extends Component {
constructor() {
super();
this.state = {
name: "React"
};
}
render() {
return (
<div>
<h1>Title</h1>
<Card>
<CardSide someProp="My Child Prop Value" />
</Card>
</div>
);
}
}
as you can see i included CardSide with property with name someProp as a child for Card rathar than inserting it inside Card Component
In the Card Component i accessed the children property as the following :
class Card extends Component {
handleCompelete = data => {
//the data here are all the data entered from the child component
//do some sorting using table name
};
render() {
return <div>
{this.props.children}
{console.log(this.props.children)}
{this.props.children.props.someProp}
</div>;
}
}
and the CardSide Component
class CardSide extends Component {
render() {
return (
<div>
{/* data here reprensets what you need to transfer to parent component */}
<button onClick={() => this.props.onCompelete(data)} >
Hello btn
</button>
</div>
);
}
}
As you can see it will get your structure more complicated and it will be hard to know who is the children for the card component without intensive tracing .
you can see the code in action via this link https://stackblitz.com/edit/react-fxuufw?file=CardSide.jsx