Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks #1

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions docs/react.asyncresult.data.md

This file was deleted.

11 changes: 0 additions & 11 deletions docs/react.asyncresult.error.md

This file was deleted.

11 changes: 0 additions & 11 deletions docs/react.asyncresult.isloading.md

This file was deleted.

92 changes: 14 additions & 78 deletions docs/react.asyncresult.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,23 @@

[Home](./index.md) > [@cerbos/react](./react.md) > [AsyncResult](./react.asyncresult.md)

## AsyncResult interface
## AsyncResult type


**Signature:**

```typescript
export interface AsyncResult<T>
export type AsyncResult<T> = {
isLoading: true;
data: undefined;
error: undefined;
} | {
isLoading: false;
data: T;
error: undefined;
} | {
isLoading: false;
data: undefined;
error: Error;
};
```

## Properties

<table><thead><tr><th>

Property


</th><th>

Modifiers


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

[data](./react.asyncresult.data.md)


</td><td>


</td><td>

T \| undefined


</td><td>


</td></tr>
<tr><td>

[error](./react.asyncresult.error.md)


</td><td>


</td><td>

Error \| undefined


</td><td>


</td></tr>
<tr><td>

[isLoading](./react.asyncresult.isloading.md)


</td><td>


</td><td>

boolean


</td><td>


</td></tr>
</tbody></table>
21 changes: 18 additions & 3 deletions docs/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,32 @@ Description
</th></tr></thead>
<tbody><tr><td>

[AsyncResult](./react.asyncresult.md)
[CerbosProviderProps](./react.cerbosproviderprops.md)


</td><td>



</td></tr>
<tr><td>
</tbody></table>

[CerbosProviderProps](./react.cerbosproviderprops.md)
## Type Aliases

<table><thead><tr><th>

Type Alias


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

[AsyncResult](./react.asyncresult.md)


</td><td>
Expand Down
3 changes: 0 additions & 3 deletions packages/react/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
plugins:
- react-hooks

extends:
- plugin:react-hooks/recommended
8 changes: 4 additions & 4 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
"React"
],
"peerDependencies": {
"react": ">=16.8.0"
"react": ">=16.13.0"
},
"dependencies": {
"@cerbos/core": "^0.16.0"
"@cerbos/core": "^0.16.0",
"use-deep-compare-effect": "^1.8.1"
},
"devDependencies": {
"@types/react": "18.2.67",
"eslint-plugin-react-hooks": "4.6.0",
"react": "18.2.0"
"eslint-plugin-react-hooks": "4.6.0"
},
"publishConfig": {
"access": "public",
Expand Down
8 changes: 6 additions & 2 deletions packages/react/src/cerbos-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
} from "@cerbos/core";
import type { ReactElement, ReactNode } from "react";
import { createContext, useMemo } from "react";
import { useDeepCompareMemoize } from "use-deep-compare-effect";

export const CerbosContext = createContext<ClientWithPrincipal | undefined>(
undefined,
Expand Down Expand Up @@ -63,9 +64,12 @@ export function CerbosProvider({
principal,
auxData,
}: CerbosProviderProps): ReactElement {
const principalMemo = useDeepCompareMemoize(principal);
const auxDataMemo = useDeepCompareMemoize(auxData);

const value = useMemo(
() => client.withPrincipal(principal, auxData),
[auxData, client, principal],
() => client.withPrincipal(principalMemo, auxDataMemo),
[client, principalMemo, auxDataMemo],
);

return (
Expand Down
5 changes: 2 additions & 3 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
export { CerbosProvider } from "./cerbos-provider";
export type { CerbosProviderProps } from "./cerbos-provider";
export { type CerbosProviderProps, CerbosProvider } from "./cerbos-provider";
export { useCerbos } from "./use-cerbos";
export {
type AsyncResult,
useCheckResource,
useCheckResources,
useIsAllowed,
} from "./use-cerbos-request";
export type { AsyncResult } from "./use-cerbos-request";
40 changes: 0 additions & 40 deletions packages/react/src/is-equal.ts

This file was deleted.

Loading