From 0bef93aeab7c3c460502b349025b97b1981c6ae0 Mon Sep 17 00:00:00 2001 From: iamangelmp Date: Wed, 15 Mar 2023 15:49:46 -0600 Subject: [PATCH] data percistance using localStorage --- src/App.jsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index e4f2bba..936f23b 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,12 +1,16 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import Header from "./components/Header"; import Form from "./components/Form"; import PatienrsList from "./components/PatienrsList"; function App() { - const [patients, setPatients] = useState([]); + const [patients, setPatients] = useState(JSON.parse(localStorage.getItem('pacientes')) ?? []); const [patient, setPatient] = useState({}); + useEffect(()=>{ + localStorage.setItem('pacientes',JSON.stringify(patients)) + },[patients]) + const deletePatient = (id) => { const updatedPatients = patients.filter((patient) => patient.id !== id); setPatients(updatedPatients);