-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce70ea4
commit d68e531
Showing
7 changed files
with
17 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 2 additions & 8 deletions
10
...ent/src/pages/detail/FormDirtyContext.tsx → ...ent/src/pages/detail/formDirtyContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
import React, { createContext, useContext, useState } from "react"; | ||
import React, { createContext, useState } from "react"; | ||
|
||
interface FormDirtyContextType { | ||
isFormDirty: boolean; | ||
setIsFormDirty: (dirty: boolean) => void; | ||
} | ||
|
||
const FormDirtyContext = createContext<FormDirtyContextType | undefined>(undefined); | ||
export const FormDirtyContext = createContext<FormDirtyContextType | undefined>(undefined); | ||
|
||
export const FormDirtyProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
const [isFormDirty, setIsFormDirty] = useState(false); | ||
|
||
return <FormDirtyContext.Provider value={{ isFormDirty, setIsFormDirty }}>{children}</FormDirtyContext.Provider>; | ||
}; | ||
|
||
export const useFormDirty = () => { | ||
const context = useContext(FormDirtyContext); | ||
if (!context) throw new Error("useFormDirty must be used within a FormDirtyProvider"); | ||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { useContext } from "react"; | ||
import { FormDirtyContext } from "./formDirtyContext.tsx"; | ||
|
||
export const useFormDirty = () => { | ||
const context = useContext(FormDirtyContext); | ||
if (!context) { | ||
throw new Error("useFormDirty must be used within a FormDirtyProvider"); | ||
} | ||
return context; | ||
}; |