AutorÃa | Ultima modificación | Ver Log |
import React, { createContext, useState } from 'react'
export const ParadigmsContext = createContext()
export default function ParadigmsProvider({ children }) {
const [paradigms, setParadigms] = useState([
{
id: 1,
title: 'Paradigm 1',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
},
{
id: 2,
title: 'Paradigm 2',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
}
])
const [showModal, setshowModal] = useState(false)
const toggleModal = () => setshowModal(!showModal)
const addParadigm = (paradigm) => {
setParadigms([
...paradigms,
{
id: paradigms.length + 1,
description: paradigm
}
])
toggleModal()
}
return (
<ParadigmsContext.Provider
value={{
setParadigms,
paradigms,
toggleModal,
showModal,
addParadigm
}}
>
{children}
</ParadigmsContext.Provider>
)
}