1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-20 13:59:40 +02:00
portainer/app/react/components/datatables/RowContext.tsx
Chaim Lev-Ari bed4257194
refactor(containers): migrate view to react [EE-2212] (#6577)
Co-authored-by: LP B <xAt0mZ@users.noreply.github.com>
2022-08-11 07:33:29 +03:00

23 lines
583 B
TypeScript

import { createContext, PropsWithChildren, useContext } from 'react';
export function createRowContext<TContext>() {
const Context = createContext<TContext | null>(null);
return { RowProvider, useRowContext };
function RowProvider({
children,
context,
}: PropsWithChildren<{ context: TContext }>) {
return <Context.Provider value={context}>{children}</Context.Provider>;
}
function useRowContext() {
const context = useContext(Context);
if (!context) {
throw new Error('should be nested under RowProvider');
}
return context;
}
}