teableio/teable

View on GitHub
packages/sdk/src/hooks/use-field-permission.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { useContext, useMemo } from 'react';
import { TablePermissionContext } from '../context/table-permission';

export type IUseFieldPermissionAction = keyof ReturnType<typeof useFieldPermission>;

export const useFieldPermission = (fieldId: string | undefined) => {
  const { field } = useContext(TablePermissionContext) ?? {};
  return useMemo(() => {
    if (!fieldId || !field?.fields) return {};
    return field.fields[fieldId] || {};
  }, [field, fieldId]);
};