Calling Secondary Function With Datepicker In React Native

- 1 answer

I'm trying to figure out how to successfully close a modal when a date is selected from the react native datepicker componenet I have. I currently set the state of a variable to the date when it's selected like so:

onDateChange={(date) => {this.setState({birthday: date})}}

However, I have a function this.toggleModal() that works on its own but I want to hit this function with the onDateChange as well but I can't seem to get it to work.

I've tried onDateChange={(date) => {this.setState({birthday: date})} => this.toggleModal()} but it errors out.

How can I compound these functions?



To run toggleModal along with setState, just place each in the callback:

onDateChange={(date) => {
                this.setState({birthday: date});

If you want to wait until setState is finished, you can furnish it with a callback as well:

this.setState({birthday: date}, this.toggleModal())};