From 2cfad20838d86f82b4921d3f1012528e75cf7490 Mon Sep 17 00:00:00 2001 From: gonza Date: Fri, 8 Apr 2022 23:47:18 -0500 Subject: [PATCH] Agrega localStorage Agrega localStorage a la lista de tareas. --- src/componentes/ListaDeTareas.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/componentes/ListaDeTareas.js b/src/componentes/ListaDeTareas.js index 44dd429..9c72c72 100644 --- a/src/componentes/ListaDeTareas.js +++ b/src/componentes/ListaDeTareas.js @@ -1,11 +1,17 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import TareaFormulario from './TareaFormulario'; import Tarea from './Tarea'; import '../hojas-de-estilo/ListaDeTareas.css'; +const estadoInicial = JSON.parse(localStorage.getItem('tareas')); + function ListaDeTareas() { - const [tareas, setTareas] = useState([]); + const [tareas, setTareas] = useState(estadoInicial || []); + + useEffect(() => { + window.localStorage.setItem('tareas', JSON.stringify(tareas)) + }, [tareas]); const agregarTarea = tarea => { if (tarea.texto.trim()) { @@ -50,4 +56,4 @@ function ListaDeTareas() { ); } -export default ListaDeTareas; \ No newline at end of file +export default ListaDeTareas;