mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-19 03:01:53 +10:00
release: v4.1.0
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import { createContext, useContext } from "react";
|
||||
import { useFormContext } from "react-hook-form";
|
||||
import { FieldPath, FieldValues } from "react-hook-form";
|
||||
import { FieldPath, FieldValues, useFormContext } from "react-hook-form";
|
||||
|
||||
type FormFieldContextValue<
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
@ -14,16 +13,16 @@ type FormItemContextValue = { id: string };
|
||||
export const FormItemContext = createContext<FormItemContextValue>({} as FormItemContextValue);
|
||||
|
||||
export const useFormField = () => {
|
||||
const fieldContext = useContext(FormFieldContext);
|
||||
const itemContext = useContext(FormItemContext);
|
||||
const fieldContext = useContext(FormFieldContext) as FormFieldContextValue | undefined;
|
||||
const itemContext = useContext(FormItemContext) as FormItemContextValue | undefined;
|
||||
const { getFieldState, formState } = useFormContext();
|
||||
|
||||
const fieldState = getFieldState(fieldContext.name, formState);
|
||||
|
||||
if (!fieldContext) {
|
||||
if (!fieldContext || !itemContext) {
|
||||
throw new Error("useFormField should be used within <FormField>");
|
||||
}
|
||||
|
||||
const fieldState = getFieldState(fieldContext.name, formState);
|
||||
|
||||
const { id } = itemContext;
|
||||
|
||||
return {
|
||||
|
||||
@ -5,12 +5,12 @@ const COLOR_SCHEME_QUERY = "(prefers-color-scheme: dark)";
|
||||
|
||||
type Theme = "system" | "dark" | "light";
|
||||
|
||||
interface UseThemeOutput {
|
||||
type UseThemeOutput = {
|
||||
theme: Theme;
|
||||
isDarkMode: boolean;
|
||||
toggleTheme: () => void;
|
||||
setTheme: Dispatch<SetStateAction<Theme>>;
|
||||
}
|
||||
};
|
||||
|
||||
export const useTheme = (): UseThemeOutput => {
|
||||
const isDarkOS = useMediaQuery(COLOR_SCHEME_QUERY);
|
||||
@ -23,15 +23,18 @@ export const useTheme = (): UseThemeOutput => {
|
||||
|
||||
useEffect(() => {
|
||||
switch (theme) {
|
||||
case "light":
|
||||
case "light": {
|
||||
setDarkMode(false);
|
||||
break;
|
||||
case "system":
|
||||
}
|
||||
case "system": {
|
||||
setDarkMode(isDarkOS);
|
||||
break;
|
||||
case "dark":
|
||||
}
|
||||
case "dark": {
|
||||
setDarkMode(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, [theme, isDarkOS]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user