Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda