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

154
Views
Can't send data to localStorage in React

I try to build an app in React with Redux and i try to get data from my Redux store and send the data to my localStorage but I have a little problem because my data in localStorage is saved like:

data    [object Object],[object Object],[object Object],[object Object]

enter image description here

This is how i get and send data to my localStorage:

import React from 'react'
import { useSelector } from 'react-redux';

function Table() {
    const myUsers = useSelector((state) => state.users.data);

    function test() {
        let data = [];

        for (let i = 0; i < myUsers.length; i++) {
            data.push(myUsers[i]);
        }

        localStorage.setItem('data', data);
    }

    test();


    return (
        <div>Table</div>
    )
}

export default Table

My database:

const database = [
    {
        id: 1,
        email: "email1@gmail.com",
        birthYear: "1999",
    },
    {
        id: 2,
        email: "email2@gmail.com",
        birthYear: "1987",
    },
    {
        id: 3,
        email: "email3@gmail.com",
        birthYear: "2005",
    },
    {
        id: 4,
        email: "email4@gmail.com",
        birthYear: "1967",
    },
];
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try this

localStorage.setItem('data', JSON.stringify(data));
about 4 years ago · Juan Pablo Isaza Report

0

localstorage doesnt allow objects but only strings to be stored in them. so convert your array into string by JSON.stringify() and then store it using localStorage.setItem() or localStorage.getItem() an while getting the array use JSON.parse() To Set

localStorage.setItem('data', JSON.stringify(data))

To Get

JSON.parse(localStorage.getItem('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!