Multiple Timepickers
Use multiple timepicker instances on the same page
Multiple Instances
Each timepicker instance is independent. You can have as many pickers as needed with different configurations.
Different Themes
#Two pickers with different themes on the same page:
Array of Pickers
#Managing multiple pickers using an array pattern:
index.tsx
import { useEffect, useRef } from 'react';import { TimepickerUI } from 'timepicker-ui';function MultiplePickersArray() {const inputRefs = useRef<HTMLInputElement[]>([]);const pickersRef = useRef<TimepickerUI[]>([]);useEffect(() => {// Initialize all pickersinputRefs.current.forEach((input, index) => {if (input) {const picker = new TimepickerUI(input, {ui: { theme: index % 2 === 0 ? 'basic' : 'dark' },});picker.create();pickersRef.current.push(picker);}});// Cleanup all pickersreturn () => {pickersRef.current.forEach(picker => picker.destroy());pickersRef.current = [];};}, []);return (<div>{['Morning', 'Afternoon', 'Evening'].map((label, i) => (<inputkey={label}ref={el => inputRefs.current[i] = el!}type="text"placeholder={`Select ${label} time`}/>))}</div>);}
Vanilla JavaScript
#Multiple pickers in vanilla JavaScript:
index.ts
import { TimepickerUI } from 'timepicker-ui';// Select all timepicker inputsconst inputs = document.querySelectorAll('.timepicker-input');// Store pickers for cleanupconst pickers = [];// Initialize each pickerinputs.forEach((input, index) => {const picker = new TimepickerUI(input, {ui: { theme: index % 2 === 0 ? 'basic' : 'dark' },clock: { type: '24h' }});picker.create();pickers.push(picker);});// Cleanup when neededfunction destroyAllPickers() {pickers.forEach(picker => picker.destroy());pickers.length = 0;}