Autoría | Ultima modificación | Ver Log |
import React, { createContext, useState } from 'react'
export const HabitsContext = createContext()
export default function HabitsProvider({ children }) {
const [habits, setHabits] = useState([
{
id: Date.now(),
name: 'Ejercicio Diario',
description:
'Realizar ejercicios físicos todos los días para mantenerse en forma.',
action: {
frequency: 'Diariamente'
},
method: {
type: '',
content: ''
},
goal: {
amount: 30 // minutos de ejercicio diario
}
}
])
const [showModal, setshowModal] = useState(false)
const toggleModal = () => setshowModal(!showModal)
const addHabit = (habit) => {
const newHabit = {
id: habits.length + 1,
...habit
}
setHabits([...habits, newHabit])
toggleModal()
}
return (
<HabitsContext.Provider
value={{
setHabits,
habits,
toggleModal,
showModal,
addHabit
}}
>
{children}
</HabitsContext.Provider>
)
}