How to create CallBack method to get value from another JS?

試著忘記壹切 提交于 2020-01-05 04:22:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!