The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/components/dashboards/usePeriodSelectorState.ts

25 lines
482 B

import { useState } from 'react';
import type { Period } from './periods';
export const usePeriodSelectorState = <TPeriod extends Period['key']>(
...periods: TPeriod[]
): [
period: TPeriod,
periodSelectorProps: {
periods: TPeriod[];
value: TPeriod;
onChange: (value: TPeriod) => void;
},
] => {
const [period, setPeriod] = useState<TPeriod>(periods[0]);
return [
period,
{
periods,
value: period,
onChange: (value): void => setPeriod(value),
},
];
};