mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 15:48:11 +00:00
fix ui
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
import React, { createContext, useContext, ReactNode } from 'react';
|
||||
import { useUnit } from '@/user-management/hooks/useUnit';
|
||||
|
||||
// Define the context type to match the return type of useUnit hook
|
||||
type UnitContextType = ReturnType<typeof useUnit> | undefined;
|
||||
|
||||
// Create context with undefined as default
|
||||
const UnitContext = createContext<UnitContextType>(undefined);
|
||||
|
||||
// Provider component
|
||||
export const UnitProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||
const unitQuery = useUnit(); // or whatever hook/query you're using to get units
|
||||
|
||||
return (
|
||||
<UnitContext.Provider value={unitQuery}>
|
||||
{children}
|
||||
</UnitContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
// Custom hook to use the context
|
||||
export const useUnitContext = () => {
|
||||
const context = useContext(UnitContext);
|
||||
if (context === undefined) {
|
||||
throw new Error('useUnitContext must be used within a UnitProvider');
|
||||
}
|
||||
return context;
|
||||
import React, { createContext, useContext, ReactNode } from 'react';
|
||||
import { useUnit } from '@/user-management/hooks/useUnit';
|
||||
|
||||
// Define the context type to match the return type of useUnit hook
|
||||
type UnitContextType = ReturnType<typeof useUnit> | undefined;
|
||||
|
||||
// Create context with undefined as default
|
||||
const UnitContext = createContext<UnitContextType>(undefined);
|
||||
|
||||
// Provider component
|
||||
export const UnitProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||
const unitQuery = useUnit(); // or whatever hook/query you're using to get units
|
||||
|
||||
return (
|
||||
<UnitContext.Provider value={unitQuery}>
|
||||
{children}
|
||||
</UnitContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
// Custom hook to use the context
|
||||
export const useUnitContext = () => {
|
||||
const context = useContext(UnitContext);
|
||||
if (context === undefined) {
|
||||
throw new Error('useUnitContext must be used within a UnitProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
Reference in New Issue
Block a user