A function that maps a timezone string to a JSX structure or other specified format.
An object containing timezone options, raw timezone data, the selected timezone, and functions to handle updates.
T The type of the options that the hook will produce for use in UI components.
import React from 'react';
import { useKosTimeZones } from '@kosdev-code/kos-ui-sdk';
const MyComponent: React.FC = () => {
// Using the hook with the default option mapper
const { selectProps } = useKosTimeZones();
return (
<div>
<label>Select Timezone:</label>
<select {...selectProps}>
{selectProps.options}
</select>
</div>
);
};
export default MyComponent;
Using the hook with a custom component and regionMap function:
import React from 'react';
import { useKosTimeZones } from '@kosdev-code/kos-ui-sdk';
// Custom component that expects an options prop
const CustomSelectComponent: React.FC<{ options: { label: string; value: string }[] }> = ({ options }) => {
return (
<select>
{options.map(option => (
<option key={option.value} value={option.value}>{option.label}</option>
))}
</select>
);
};
// Custom regionMap function to map timezones to the required format for CustomSelectComponent
const customRegionMap = (timezone: string) => ({
label: `Timezone: ${timezone}`,
value: timezone
});
const MyComponent: React.FC = () => {
// Using the hook with the custom regionMap function
const { options } = useKosTimeZones(customRegionMap);
return (
<div>
<label>Select Timezone:</label>
<CustomSelectComponent options={options} />
</div>
);
};
export default MyComponent;
Custom React hook for managing and interacting with timezone data. It fetches timezone information from the RegionInfoModel and facilitates timezone selection in a React application.