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

256
Views
Why is a stored object not displayed?

I kept the values entered in the bmi calculation project as an object in localStorage^. I'm having trouble trying to view it. I have an error which is "Cannot read properties of null (reading 'DaTe')". What can I do?

Here are the values I declared:

function storeData() {
        var today = new Date();  
        var date = (today.getMonth()+1)+'-'+today.getDate()+'-'+today.getFullYear();
        let formData = JSON.parse(localStorage.getItem('formData')) || [];
        formData.push({
            DaTe : date,
            resultBmi: bmiResult,
            Name: values.name,
        });
        localStorage.setItem('formData', JSON.stringify(formData));
    }
    useEffect(()=>{
        storeData();
    },[bmiResult]) 

Calculations.js: 
function Calculations() { 
    return (
        <div className="calc-page" >
            <h2>CALCULATIONS</h2>
            <table id="records">
                <tbody>
                    <tr>
                    <th>Date</th>
                    <th>Name</th>
                    <th>BMI</th>
                    </tr>
                    {(localStorage.getItem("formData")) && JSON.parse(localStorage.getItem("formData")).map(data=>{
                    <tr>
                    <td>{data.DaTe}</td>
                    <td>{data.Name}</td>
                    <td>{data.resultBmi}</td>
                    </tr>
                    })}
                </tbody>
            </table>
            <button className="btn-clear">Clear</button>
        </div>
    );
} 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should use map() method for rendering data because forEach returns undefined while map returns a new array:

Working example

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!