Skip to content

Instantly share code, notes, and snippets.

@jere-co
jere-co / DOBPicker.tsx
Created July 4, 2023 05:46 — forked from tanishqsh/DOBPicker.tsx
DOB Calendar
/**
/DOBPicker.tsx
**/
'use client';
import * as React from 'react';
import { format, subYears } from 'date-fns';
import { cn } from '@/lib/utils';
import { Button } from '@/components/ui/button';

This middleware does a few interesting things:

  • Ensures a url shape in the zustand store, where we'll store URL information.
  • Assumes we will be storing our url state slice in the ?state search parameter after it has been stringified and base 64 encoded.
  • On creation, decodes stores state from the ?state search parameter into the url slice of our store.
  • After each state update, updates the ?state search parameter with the new url state slice.
  • Sets up an event listener that listens for popstate and re-decodes the state from the URL into our store.