Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
Setting maxDate in Material UI DatePicker Component

I have been struggling to get the maxDate prop on the Material UI DatePicker component to work as expected. That is, dates after the maxDate are disabled.

My use case required setting the maxDate to +60 days from the current Date() with dates thereafter disabled.

Please see my answer for a solution that is working on my end.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

My working solution via CodeSandbox found here.

If you prefer the code instead of CodeSandbox:

index.js

import React from "react";
import App from "./App.jsx";
import DateFnsUtils from "@date-io/date-fns";
import { render } from "react-dom";
import { MuiPickersUtilsProvider } from "@material-ui/pickers";
import "./App.css";

render(
  <MuiPickersUtilsProvider utils={DateFnsUtils}>
    <App />
  </MuiPickersUtilsProvider>,
  document.querySelector("#root")
);

App.jsx

import React, { useState } from "react";
import DateFnsUtils from "@date-io/date-fns";
import moment from "moment";
import { DatePicker, MuiPickersUtilsProvider } from "@material-ui/pickers";

function App() {
  const dayjs = require("dayjs");
  const [selectedDate, handleDateChange] = useState(new Date());

  // function for setting the maxDate for DatePicker
  // return value is current date + X days
  const setMaxDate = (daysToAdd) => {
    const now = new Date();
    const nowPlusDays = now.setDate(now.getDate() + daysToAdd);
    return moment(dayjs(nowPlusDays).format("YYYY-MM-DD"));
  };

  return (
    <MuiPickersUtilsProvider utils={DateFnsUtils}>
      <DatePicker
        value={selectedDate}
        onChange={handleDateChange}
        maxDate={setMaxDate(60)}
      />
    </MuiPickersUtilsProvider>
  );
}

export default App;
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda