Skip to content

Manually select a range with useSelectRange? #1962

Answered by gpbl
Gusis93 asked this question in Support
Discussion options

You must be logged in to vote

@Gusis93 Let me understand - are you trying to add a button to select the whole month or today or yesterday?

Screen.Recording.2023-10-31.at.18.17.56.mov

See https://codesandbox.io/s/react-day-picker-forked-twvvdp?file=/src/App.tsx

export default function App() {
  const [month, setMonth] = useState(new Date());
  const [selectedRange, setSelectedRange] = useState();

  const selectWholeMonth = () =>
    setSelectedRange({
      from: startOfMonth(month),
      to: endOfMonth(month)
    });

  const selectMonthButton = (
    <button onClick={selectWholeMonth}>
      Select {format(month, "MMMM YYY")}
    </button>
  );

  return (
    <DayPicker
      mode="range"
      month={month}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Gusis93
Comment options

@gpbl
Comment options

Answer selected by Gusis93
@Gusis93
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants