first commit
This commit is contained in:
26
src/Contexts.js
Normal file
26
src/Contexts.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { createContext } from "preact";
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
import usePlants from "./hooks/PlantsHook";
|
||||
import { useLocalStorage } from "./hooks/LocalStorageHook"
|
||||
import useUser from "./hooks/UserHook";
|
||||
|
||||
export const UserContext = createContext()
|
||||
export const PlantsContext = createContext()
|
||||
|
||||
export default function ContextsProviders({children}) {
|
||||
|
||||
const [data, setData] = useLocalStorage('data', {})
|
||||
const [user, setUser] = useUser(data, setData)
|
||||
const {plants, addPlant, editPlant, removePlant, addAction, doneTask, history} = usePlants(data, setData)
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
console.log('first', user);
|
||||
}, [user])
|
||||
|
||||
return <UserContext.Provider value={[user, setUser]}>
|
||||
<PlantsContext.Provider value={{plants, addPlant, editPlant, removePlant, addAction, doneTask, history}}>
|
||||
{children}
|
||||
</PlantsContext.Provider>
|
||||
</UserContext.Provider>
|
||||
}
|
||||
Reference in New Issue
Block a user