Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const ChartWrapper: React.FC = ({ entityType, selectedIds }) => {
const [storedStartAndEndDates, setStoredStartAndEndDates] = useLocalStorage<
[string, string]
>("home_selectedDates", [defaultStartDate.toISO(), defaultEndDate.toISO()]);
const getStartDate = () =>
storedStartAndEndDates === null
? defaultStartDate
: DateTime.fromISO(storedStartAndEndDates[0]);
const getEndDate = () =>
storedStartAndEndDates === null
? defaultEndDate
: DateTime.fromISO(storedStartAndEndDates[1]);
const getStartAndEndDates = (): [DateTime, DateTime] => [
getStartDate(),
getEndDate()
];
const useStoredDatePair = (
storageKey: string,
defaultStartDate: DateTime,
defaultEndDate: DateTime
) => {
const [storedStartAndEndDates, setStoredStartAndEndDates] = useLocalStorage<[string, string]>(
storageKey + "_selectedDates",
[defaultStartDate.toISO(), defaultEndDate.toISO()]
);
const getStartDate = () =>
storedStartAndEndDates === null
? defaultStartDate
: DateTime.fromISO(storedStartAndEndDates[0]);
const getEndDate = () =>
storedStartAndEndDates === null ? defaultEndDate : DateTime.fromISO(storedStartAndEndDates[1]);
const getStartAndEndDates = (): [DateTime, DateTime] => [getStartDate(), getEndDate()];
const setStartAndEndDates = (startDate: DateTime, endDate: DateTime) => {
setStoredStartAndEndDates([startDate.toISO(), endDate.toISO()]);