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

463
Visualizações
How can I check if url parameters exist with formik register form? Is there a ready exported function that does this from formik?

I want to assign a value to one of the initial values (referrerId), based on whether URL parameters exist or not. I have left out the other code which I believe is irrelevant for this question. When the form loads, I want the referrerId field to be prepopulated with id extracted from URL parameters.

<Form
  initialValues={{
    referrerId: // if there are no parameters set string "none" : referrer's id, which is extracted from params,
  }}
>

   <FormField 
      label="Referrer's Id"
      name="referrerId"
      placeholder="Referrer's Id"
      type="text"
   /> 

</Form>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

One way to make this possible is by using the URLSearchParams javascript interface.

const parameters = new URLSearchParams(window.location.search);

<Form
  initialValues={{
    referrerId: `${parameters.get('referrer-id')}`,
  }}
>

   <FormField 
      label="Referrer's Id"
      name="referrerId"
      placeholder="Referrer's Id"
      type="text"
   /> 

</Form>

and your url will look something like

https://mycoolwebsite.com/somepage?referrer-id=23221
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