Topic: Time Picker Component
salphonso free asked 5 years ago
Hello. I have successfully implemented the time picker and all works great but one thing I am need to do is update the object state with the current time. There is no onChange event that can be triggered only a getValue option. Any advice on how I can have that update the state based on the id given to the picker?
Jakub Mandra staff answered 5 years ago
Hi,
You could pass that id as a function argument:
import React, { Component } from "react";
import { MDBTimePicker } from "mdbreact";
class TimePickerPage extends Component {
state = {
timePickerOne: '12:30'
}
getPickerValue = (id, value) => this.setState({ [id]: value });
render() {
return (
<MDBTimePicker id="timePickerOne" getValue={(value) => this.getPickerValue("timePickerOne", value)} hours={12} minutes={30} />
);
}
}
export default TimePickerPage;
salphonso free commented 5 years ago
Thanks Jakub. This is what I ended up doing and it worked perfectly. It's funny how much we overthink things some times and it ends up being a straightforward answer. Thanks again or the help.
Jakub Mandra staff commented 5 years ago
Glad I could help.
Keep hacking! :)
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Free
- Premium support: No
- Technology: MDB React
- MDB Version: 4.8.4
- Device: Website
- Browser: Chrome
- OS: Mac OSX
- Provided sample code: No
- Provided link: No