Skip to content

Commit 073f642

Browse files
committed
Apply AI PR feedback
Change memoization level for ENSApi options object
1 parent 5edb862 commit 073f642

5 files changed

Lines changed: 18 additions & 15 deletions

File tree

apps/ensadmin/src/components/providers/selected-ensnode-provider.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import type { PropsWithChildren } from "react";
3+
import { type PropsWithChildren, useMemo } from "react";
44

55
import { createEnsApiOptions, EnsApiProvider } from "@ensnode/ensnode-react";
66

@@ -21,9 +21,15 @@ export function SelectedEnsApiProvider({ children }: PropsWithChildren) {
2121
const selectedConnection = useSelectedConnection();
2222

2323
if (selectedConnection.validatedSelectedConnection.isValid) {
24-
const options = createEnsApiOptions({
25-
url: selectedConnection.validatedSelectedConnection.url,
26-
});
24+
const selectedConenctionUrl = selectedConnection.validatedSelectedConnection.url;
25+
const options = useMemo(
26+
() =>
27+
createEnsApiOptions({
28+
url: selectedConenctionUrl,
29+
}),
30+
[selectedConenctionUrl],
31+
);
32+
2733
return <EnsApiProvider options={options}>{children}</EnsApiProvider>;
2834
} else {
2935
// TODO: Logic here needs a deeper refactor to recognize the difference

packages/ensnode-react/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,19 @@ function DisplayPrimaryNames() {
126126

127127
### EnsApiProvider
128128

129-
The provider component that supplies ENSNode configuration to all child components.
129+
The provider component that supplies ENSApi options to all child components.
130130

131131
```tsx
132132
interface EnsApiProviderProps {
133-
config: ENSNodeConfig;
133+
options: EnsApiProviderOptions;
134134
queryClient?: QueryClient;
135135
queryClientOptions?: QueryClientOptions;
136136
}
137137
```
138138

139139
#### Props
140140

141-
- `config`: ENSNode configuration object
141+
- `options`: ENSApi options object
142142
- `queryClient`: Optional TanStack Query client instance (requires manual QueryClientProvider setup)
143143
- `queryClientOptions`: Optional Custom options for auto-created QueryClient (only used when queryClient is not provided)
144144

@@ -235,7 +235,7 @@ The `EnsApiProvider` automatically creates and manages a QueryClient for you. Ca
235235
```tsx
236236
// Simple setup - no TanStack Query knowledge needed
237237
<EnsApiProvider
238-
config={config}
238+
options={options}
239239
queryClientOptions={{
240240
defaultOptions: {
241241
queries: {
@@ -268,7 +268,7 @@ const queryClient = new QueryClient({
268268
});
269269

270270
<QueryClientProvider client={queryClient}>
271-
<EnsApiProvider config={config} queryClient={queryClient}>
271+
<EnsApiProvider options={options} queryClient={queryClient}>
272272
<App />
273273
</EnsApiProvider>
274274
</QueryClientProvider>;

packages/ensnode-react/src/hooks/useResolvedIdentity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { usePrimaryName } from "./usePrimaryName";
2323
* @param parameters - Configuration object for the hook
2424
* @param parameters.identity - An {@link UnresolvedIdentity} containing the {@link DefaultableChainId}
2525
* and {@link Address} to resolve.
26-
* @param parameters.namespaceId - The {@link ENSNamespaceId} that `identity.chainId` should be interpreted
26+
* @param parameters.namespace - The {@link ENSNamespaceId} that `identity.chainId` should be interpreted
2727
* through (via {@link getResolvePrimaryNameChainIdParam}) to determine the literal
2828
* chainId that should be used for ENSIP-19 primary name resolution.
2929
* @param parameters.accelerate - Whether to attempt Protocol Acceleration (default: false)

packages/ensnode-react/src/provider.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ function EnsApiInternalProvider({
3333
children?: React.ReactNode;
3434
options: EnsApiProviderOptions;
3535
}) {
36-
// Memoize the options to prevent unnecessary re-renders
37-
const memoizedOptions = useMemo(() => options, [options]);
38-
39-
return createElement(EnsApiContext.Provider, { value: memoizedOptions }, children);
36+
return createElement(EnsApiContext.Provider, { value: options }, children);
4037
}
4138

4239
export function EnsApiProvider(parameters: React.PropsWithChildren<EnsApiProviderProps>) {

packages/ensnode-react/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
} from "@ensnode/ensnode-sdk";
1616

1717
/**
18-
* Configuration options for the ENSNode provider
18+
* Configuration options for the ENSApi provider
1919
*/
2020
export interface EnsApiProviderOptions {
2121
/** The ENSApi client configuration */

0 commit comments

Comments
 (0)