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

176
Views
Exception for null fetched data React

I am mapping fetched data like this in React. I am printing name, column and row to the paragraph so whenever it is null, it prints just null null null, but if warehouse_name is null I need to transfer all values to some String like "Undefined" instead of these tree null.

There can be maybe better solution with using some string method for paragraph instead of this?

  const transformedData = data.order_items.map((invoiceData) => {
    return {
      alternative_warehouse_position: invoiceData.alternative_warehouse_position,
      warehouse_column: invoiceData.warehouse_column,
      warehouse_name: invoiceData.warehouse_name,
      warehouse_row: invoiceData.warehouse_row,
    };
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You could use the nullish coalescing operator ??.

const FALLBACK_STRING = "(not set)";
return {
  alternative_warehouse_position: invoiceData.alternative_warehouse_position ?? FALLBACK_STRING,
  warehouse_column: invoiceData.warehouse_column ?? FALLBACK_STRING,
  warehouse_name: invoiceData.warehouse_name ?? FALLBACK_STRING,
  warehouse_row: invoiceData.warehouse_row ?? FALLBACK_STRING,
};
about 4 years ago · Juan Pablo Isaza Report

0

3 ways to do it:

  • Using the "?" to check if its null. Example: ${Condition} ? ${is true} : ${is false}.

  • Using the new null-checking syntax. Example: ${Value} ?? ${the replacement if its null}

  • Using the OR operator, which enhances backwards capabilities. Example: ${first condition} || ${Second to replace if the first is false}

Note: Null counts as false

about 4 years ago · Juan Pablo Isaza Report

0

If I understand you correctly, you want to replace all three values with one string if invoiceData.warehouse_name is null. You can use the ternary operator (?:) for that.

const transformedData = data.order_items.map(
  invoiceData => !!invoiceData.warehouse_name ?
    {
      alternative_warehouse_position: invoiceData.alternative_warehouse_position,
      warehouse_column: invoiceData.warehouse_column,
      warehouse_name: invoiceData.warehouse_name,
      warehouse_row: invoiceData.warehouse_row
    } :
    "No data"
);
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!