Consider two react components. One is a form component. The other a fancy date picker I have rolled myself. The date picker should make the currently selected date available to it's parent component. What is the best way to do this? Should the date picker report back up to it's parent component somehow? If so how? Or would a better solution be to use alt.js in my project to publish an action from the date picker that get's updated in my form component?
The best way to do this is to add an onChange
to the props of the child component. Handle this onChange
event in the parent component by passing it a callback. There are two advantages to this approach. Firstly you don't rely on any other components while the user changes the state of the form. The second advantage is that all your custom form components can implement the same interface allowing for reuse.