React 18 and Vite (#4510)
This commit is contained in:
parent
1bb1b13f6d
commit
21613fa602
244 changed files with 4547 additions and 8933 deletions
|
@ -1,24 +1,25 @@
|
|||
import React, { memo } from 'react';
|
||||
import { usePermissions } from '@/plugins/usePermissions';
|
||||
import type { ReactNode } from 'react';
|
||||
import { memo } from 'react';
|
||||
import isEqual from 'react-fast-compare';
|
||||
import { usePermissions } from '@/plugins/usePermissions';
|
||||
|
||||
interface Props {
|
||||
action: string | string[];
|
||||
matchAny?: boolean;
|
||||
renderOnError?: React.ReactNode | null;
|
||||
children: React.ReactNode;
|
||||
renderOnError?: ReactNode | null;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
const Can = ({ action, matchAny = false, renderOnError, children }: Props) => {
|
||||
function Can({ action, matchAny = false, renderOnError, children }: Props) {
|
||||
const can = usePermissions(action);
|
||||
|
||||
return (
|
||||
<>
|
||||
{(matchAny && can.filter((p) => p).length > 0) || (!matchAny && can.every((p) => p))
|
||||
? children
|
||||
: renderOnError}
|
||||
{(matchAny && can.filter(p => p).length > 0) || (!matchAny && can.every(p => p)) ? children : renderOnError}
|
||||
</>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default memo(Can, isEqual);
|
||||
const MemoizedCan = memo(Can, isEqual);
|
||||
|
||||
export default MemoizedCan;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue