forked from openfoodfacts/taxonomy-editor
-
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.
Fixed the current requirements for issue openfoodfacts#474
- Loading branch information
1 parent
f93b60b
commit 7484125
Showing
4 changed files
with
107 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { createContext, useState, useContext, ReactNode } from 'react'; | ||
|
||
// Define types for the context | ||
interface AppContextType { | ||
taxonomyName: string; | ||
setTaxonomyName: (value: string) => void; | ||
ownerName: string; | ||
setOwnerName: (value: string) => void; | ||
description: string; | ||
setDescription: (value: string) => void; | ||
clearContext: () => void; // Correct return type here | ||
} | ||
|
||
// Create the context with default values | ||
const AppContext = createContext<AppContextType | undefined>(undefined); | ||
|
||
// Create a provider component | ||
export const AppProvider = ({ children }: { children: ReactNode }) => { | ||
const [taxonomyName, setTaxonomyName] = useState(""); | ||
const [ownerName, setOwnerName] = useState(""); | ||
const [description, setDescription] = useState(""); | ||
|
||
const clearContext = () => { | ||
setTaxonomyName(""); | ||
setOwnerName(""); | ||
setDescription(""); | ||
}; | ||
|
||
return ( | ||
<AppContext.Provider | ||
value={{ | ||
taxonomyName, | ||
setTaxonomyName, | ||
ownerName, | ||
setOwnerName, | ||
description, | ||
setDescription, | ||
clearContext, | ||
}} | ||
> | ||
{children} | ||
</AppContext.Provider> | ||
); | ||
}; | ||
|
||
// Create a custom hook to use the context | ||
export const useAppContext = (): AppContextType => { | ||
const context = useContext(AppContext); | ||
if (!context) { | ||
throw new Error('useAppContext must be used within an AppProvider'); | ||
} | ||
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