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

152
Vistas
Getting "Object is of type 'unknown'." error on location.state

I'm using the useLocation hook like this -> const location = useLocation();. Then I try to pass it to the prop of a React element like this:

 <DatePicker
     emphasize={location.state?.fields?.some(
         (f: string) => f === 'endDate'
     )}
     data-testid="collection-form-end-date"
     type="datetime-local"
     {...field}
 />

But I get the location.state underscored and the following error -> Object is of type 'unknown'.

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

0

Managed to figure this out by adding the field to useLocation()

   const location = useLocation<{
      fields: unknown;
   }>();

I don't know if it will work or not but you can try.

about 4 years ago · Juan Pablo Isaza Denunciar

0

In my opinion to handle this issue you can try these two ways: On the first try, refer to the following question link and test its answer: React TypeScript: Correct type for useLocation() from react-router-dom . If it didn't work for you properly, try following way using lodash library:

import get from 'lodash/get'
 
 ...
 
 <DatePicker
 get(location, 'state.procedureDetail.description', '')
     emphasize={get(location, 'state.some') &&
       get(location, 'state.some')(
           (f: string) => f === 'endDate'
       )
     }
     data-testid="collection-form-end-date"
     type="datetime-local"
     {...field}
 />

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