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

100
Views
check for null when destructuring data with useSelector

How can I check for null when destructuring my data:

   const {
      vehicles: {
         data: { reminderVehicles },
      },
   } = useSelector((state) => state);

The below code gives me

null is not an object, evaluating vehicles.data.reminderVehicles

   document.getElementById("VehicleRegistration").value = "${
        (prepopVehicleReg && reminderVehicles[0]?.Registration) || ""
     }";
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can always assign a default value to it.

const myData = {
  one: 1,
  two: 2,
  nested: {
    three: 1
  }
};

const {one = null} = myData;
const {five = null} = myData;
const {nested: {three}} = myData;
const {nested: {six = 'Default'}} = myData;


console.log({
 one, 
 three,
 five, 
 six
});

In your case, it should be (assuming reminderVehicles is an array)

const {
    vehicles: {
        data: {
            reminderVehicles
        } = {
            reminderVehicles: []
        }
    } = {}
} = useSelector((state) => state);

But this is not readable and looks very complicated

about 4 years ago · Santiago Trujillo 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!