score:1

The problem is that you're setting mobileDetails to an empty array on each form submitting. To resolve this issue, You have 2 ways:

First: Saving mobile details in an array using useState hooks. Using this way on each page refresh you will lose your data again.

Second:(Recommended if not losing data in refresh is important to you)

Initialize your mobileDetails array using localStorage in your handleSubmit. Refactored code should be something like this:

const handleSubmit = () => {
    //Getting data from localStorage
    const savedMobileDetails = localStorage.getItem('data')

    //Check if data is available to parse or seeting empty array
    const mobileDetails = savedMobileDetails ? JSON.parse(savedMobileDetails) : []

    //Saving new data
    localStorage.setItem('data',JSON.stringify([...mobileDetails,detail]))
}

Related Query

More Query from same tag