Added Sidebar
This commit is contained in:
25
src/contexts/ActiveNoteContext.tsx
Normal file
25
src/contexts/ActiveNoteContext.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createContext, Dispatch, SetStateAction, ReactNode, useContext, useState } from "react";
|
||||
import { Note } from "../models/Note";
|
||||
|
||||
type ActiveNoteType = {
|
||||
currentNote: Note | null;
|
||||
setCurrentNote: Dispatch<SetStateAction<Note | null>>;
|
||||
}
|
||||
|
||||
const ActiveNote = createContext<ActiveNoteType | null>(null);
|
||||
|
||||
export function NoteProvider({ children }: { children: ReactNode }) {
|
||||
const [currentNote, setCurrentNote] = useState<Note | null>(null);
|
||||
|
||||
return (
|
||||
<ActiveNote.Provider value={{ currentNote, setCurrentNote }}>
|
||||
{children}
|
||||
</ActiveNote.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useNote() {
|
||||
const context = useContext(ActiveNote);
|
||||
if (!context) throw new Error("useNote must be used from within ActiveNote.Provider")
|
||||
return context;
|
||||
}
|
||||
Reference in New Issue
Block a user