I am using this helper to display a datepicker
component
<%= react_component "MyDatePicker", startDate: '', endDate: ''%>
I want to pass javascript values to startDate
and endDate
props. Any possible way to do this?
I am using this helper to display a datepicker
component
<%= react_component "MyDatePicker", startDate: '', endDate: ''%>
I want to pass javascript values to startDate
and endDate
props. Any possible way to do this?
Fixed this by using
Pubsub
. What I did ispublish
the user selected values in the javascript first. Then on react parent component lifecycle method subscribed to the previouslypublished
event and usesetState
to change thestate
based on that.Now am on mobile but i will publish the code for clarity once i got access to a pc.
update
Using
pubsub
is easy. First we need topublish
the required from anywhere using javascriptHere I just pass a dates object. You can pass anything. Then in react's
componentDidMount
state I subscribe to thisHere the first is object we are expecting and the callback
so here is the call back function here you can do anything like ajax call, set state, or anything
And finally unsubscribe when component
unmounts
This is how I implemented it. I no longer have the code but I hope you got the point.