I am new in React and I would like to assign parent props to child component's variable like=>
this.setState({
tsmodel : props.dataSource
})
Here is parent code =>
<TimeSheetDialog
fromdate={this.state.fromdate}
todsate={this.state.todate}
show={this.state.showmodel}
onHide={this.handleModelShow}
dataSource={this.state.selectedtsrow}/>
I pass this selectedtsrow
variable to the child component.
Here is my child code=>
export default class TimeSheetDialog extends React.Component{
constructor(props){
super(props);
this.state = {
tsmodel : props.dataSource
};
}
render(){
return(
.
.
.
<DatePicker
selected={ this.state.tsmodel.tsdate }
onChange={(e)=>this.handleDateChange("tsdate",e)}
dateFormat="dd-MM-yyyy"
/>
)
}
}
I can't use like that because this tsmodel
is always undefined
.
My requirement is I don't want to use this.props.dataSource.tsdate
and I would like to use this.state.tsmodel.tsdate
.
How can I set this parent props to the child variable? Am I miss logic?