score:0

const [name, setName] = localStorage.setItem('myData', JSON.stringify(carts));

score:0

const [cards, setCards] = useState(JSON.parse((localStorage.getItem('carts'))));

score:0

import React, { useState } from 'react';
const carts = JSON.parse(localStorage.getItem('cartProduct'));

function Data() {
  const [name, setName] = useState(carts);
  function handleChange(e) {
    const {value} = e.target
    setName(()=> value)
  }
  return (
    <div>
      <input
        type="text"
        placeholder=" product"
        value={name} //value from productname with id: 001
        onChange={handleChange}
      />
      <input
        type="text"
        placeholder="product"
        value={name} //value from productname with id: 002
        onChange={handleChange}
      />
    </div>
  );
}

Related Query

More Query from same tag