28 lines
613 B
TypeScript
28 lines
613 B
TypeScript
"use client"
|
|
|
|
import { CrudShowResponse, ExpensesClient } from "@garage/api"
|
|
import { createContext, useContext } from "react"
|
|
|
|
export type ExpenseContextValue = CrudShowResponse<ExpensesClient>['data']
|
|
|
|
|
|
const ExpenseContext = createContext<ExpenseContextValue | null>(null)
|
|
|
|
export function ExpenseProvider({
|
|
expense,
|
|
children,
|
|
}: {
|
|
expense: ExpenseContextValue
|
|
children: React.ReactNode
|
|
}) {
|
|
return (
|
|
<ExpenseContext.Provider value={expense}>
|
|
{children}
|
|
</ExpenseContext.Provider>
|
|
)
|
|
}
|
|
|
|
export function useExpense() {
|
|
return useContext(ExpenseContext)
|
|
}
|