Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!