|
1 | 1 | 'use client'
|
2 | 2 |
|
3 |
| -import { createContextState } from 'foxact/context-state' |
| 3 | +import { createContext, useContext, useState } from 'react' |
| 4 | +import type { Dispatch, FC, PropsWithChildren, SetStateAction } from 'react' |
4 | 5 |
|
5 |
| -export const [CurrentNoteIdProvider, useCurrentNoteId, useSetCurrentNoteId] = |
6 |
| - createContextState<undefined | string>(undefined) |
| 6 | +// export const [CurrentNoteIdProvider, useCurrentNoteId, useSetCurrentNoteId] = |
| 7 | +// createContextState<undefined | string>(undefined) |
| 8 | + |
| 9 | +const CurrentNoteIdContext = createContext(undefined as undefined | string) |
| 10 | + |
| 11 | +const SetCurrentNoteIdContext = createContext< |
| 12 | + Dispatch<SetStateAction<string | undefined>> |
| 13 | +>(() => void 0) |
| 14 | + |
| 15 | +const CurrentNoteIdProvider: FC< |
| 16 | + { |
| 17 | + initialNoteId?: string |
| 18 | + } & PropsWithChildren |
| 19 | +> = ({ initialNoteId, children }) => { |
| 20 | + const [currentNoteId, setCurrentNoteId] = useState(initialNoteId) |
| 21 | + return ( |
| 22 | + <CurrentNoteIdContext.Provider value={currentNoteId}> |
| 23 | + <SetCurrentNoteIdContext.Provider value={setCurrentNoteId}> |
| 24 | + {children} |
| 25 | + </SetCurrentNoteIdContext.Provider> |
| 26 | + </CurrentNoteIdContext.Provider> |
| 27 | + ) |
| 28 | +} |
| 29 | +const useCurrentNoteId = () => { |
| 30 | + return useContext(CurrentNoteIdContext) |
| 31 | +} |
| 32 | +const useSetCurrentNoteId = () => { |
| 33 | + return useContext(SetCurrentNoteIdContext) |
| 34 | +} |
| 35 | + |
| 36 | +export { useCurrentNoteId, useSetCurrentNoteId, CurrentNoteIdProvider } |
0 commit comments