-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Vendor Count in descriptions (#5210)
- Loading branch information
1 parent
667b2dd
commit 4fbe90d
Showing
12 changed files
with
112 additions
and
21 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
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
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,46 @@ | ||
import { createContext, h } from "preact"; | ||
import { FC } from "preact/compat"; | ||
import { | ||
Dispatch, | ||
StateUpdater, | ||
useContext, | ||
useMemo, | ||
useState, | ||
} from "preact/hooks"; | ||
|
||
interface VendorButtonContextProps { | ||
vendorCount?: number; | ||
setVendorCount: Dispatch<StateUpdater<number | undefined>>; | ||
} | ||
|
||
export const VendorButtonContext = createContext< | ||
VendorButtonContextProps | Record<any, never> | ||
>({}); | ||
|
||
export const VendorButtonProvider: FC = ({ children }) => { | ||
const [vendorCount, setVendorCount] = useState<number>(); | ||
|
||
const value: VendorButtonContextProps = useMemo( | ||
() => ({ | ||
vendorCount, | ||
setVendorCount, | ||
}), | ||
[vendorCount, setVendorCount], | ||
); | ||
|
||
return ( | ||
<VendorButtonContext.Provider value={value}> | ||
{children} | ||
</VendorButtonContext.Provider> | ||
); | ||
}; | ||
|
||
export const useVendorButton = () => { | ||
const context = useContext(VendorButtonContext); | ||
if (!context || Object.keys(context).length === 0) { | ||
throw new Error( | ||
"useVendorButton must be used within a VendorButtonProvider", | ||
); | ||
} | ||
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