问题
I have create CustomDatePicker.JS
file for datePicker, for Android use the DatePickerAndroid
and for ios use DatePickerIOS
, and its use in my another Profile.js
file. I use like below.
<CustomDatePicker ref='modal'></CustomDatePicker>
Now whenever will select the date, CustomDatePicker.JS
class get the value but I want to the date value in Profile.js
. So how can get date value in profile.
CustomDatePicker.JS
: Here Will get date and time log.
Profile.js
: Want to date which is selected on CustomDatePicker.
I hope, You are underStand...
Thanks.
回答1:
In your Profile.js
, i.e Profile component
you can pass some callback fn as props like,
<CustomDatePicker
mode="date"
onDateChange={date => this.onDateChange(date)}
ref='modal'>
</CustomDatePicker>
In you CustomDatePicker.js
, i.e CustomDatePicker component
where you have defined DatePickerIOS
, you can use those props.
<DatePickerIOS
{...this.props}
/>
来源:https://stackoverflow.com/questions/48987496/how-to-create-callback-method-to-get-value-from-another-js