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

237
Visualizações
How to submit empty value and make it send None as a string react

I am trying to send an empty value and when I submit it, it send "None" to the data.

Here is my code base:

  const [addLoanClause, setAddLoanClause] = useState("");

  const handleSubmit = () => {

if (id) {
  var loanProposalDetailsUpdateObject = {
    ...
    addLoanClause: addLoanClause,
  };
  if (dataChanged(loanProposalDetailsUpdateObject)) {
    updateUserLoanProposalRequest({
      loanProposalDetails: loanProposalDetailsUpdateObject,
    }).then(() => {
      routeToNextPage(isUserLoanRequestInitiator, router, id);
    });
  }
  else {
    routeToNextPage(isUserLoanRequestInitiator, router, id);
  }
} else {
  props
    .createUserLoanRequest({
      requestType: transactionType,
      status: "draft",
      loanProposalDetails: {
        ...
        addLoanClause: addLoanClause,
      },
    })
    .then(data => {
      routeToNextPage(isUserLoanRequestInitiator, router, data.id);
    });
   }
 };

<DynamicWidthInput
  id="addLoanClause"
  value={addLoanClause}
  type="textarea"
  placeholder="1000 characters"
  error={showErrors && getError("addLoanClause")}
  onChange={e =>
    handleDynamicStateChange(e, setAddLoanClause)
  }
  size={"xxl"}
  rows="5"
/>

How can I achieve it if I want to send empty value in textarea and it will automatically know to send string "None" to the data?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could define your value to be sent using a ternary referencing the length of the input:

const output = addLoanClause.length > 0 ? addLoanClause : 'None'

So if the length of the input is greater than zero, use the input. Else, use 'None'

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