how do I pass data between components using the < Route/ >
tag of react-router-dom
? (without using state machines such as redux)
data can be transmitted in this way when it is normal between the two components
getDataFromSub = (data) =>{
//
console.log(data)
}
<div>
<div>
<SubComponent setDataToParent={this.getDataFromSub}/>
</div>
</div>
state={
data:[
{id:1,value:"aaa"},
{id:2,value:"bbb"},
{id:3,value:"ccc"},
]
}
//
this.props.setDataToParent(this.state.data)
<div>
</div>
but you can"t pass data like this after using the Route
tag
<div>
<div>
//
<Route path={"/get_data"} component={SubComponent} setDataToParent={this.getDataFromSub} />
</div>
</div>