Skip to content

Commit

Permalink
memoize selected region
Browse files Browse the repository at this point in the history
  • Loading branch information
bnussman committed Mar 27, 2024
1 parent 7b86f37 commit 8a453e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import { useWatch } from 'react-hook-form';

import { Divider } from 'src/components/Divider';
Expand All @@ -18,7 +18,10 @@ export const Addons = () => {

const { data: regions } = useRegionsQuery();

const selectedRegion = regions?.find((r) => r.id === regionId);
const selectedRegion = useMemo(
() => regions?.find((r) => r.id === regionId),
[regions, regionId]
);

const isEdgeRegionSelected = selectedRegion?.site_type === 'edge';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import { useController, useWatch } from 'react-hook-form';

import { Checkbox } from 'src/components/Checkbox';
Expand Down Expand Up @@ -38,7 +38,10 @@ export const Backups = () => {
type,
});

const selectedRegion = regions?.find((r) => r.id === regionId);
const selectedRegion = useMemo(
() => regions?.find((r) => r.id === regionId),
[regions, regionId]
);

const isAccountBackupsEnabled = accountSettings?.backups_enabled ?? false;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { CreateLinodeRequest } from '@linode/api-v4';
import React from 'react';
import React, { useMemo } from 'react';
import { useController, useWatch } from 'react-hook-form';

import { Checkbox } from 'src/components/Checkbox';
Expand All @@ -9,6 +8,8 @@ import { Typography } from 'src/components/Typography';
import { useRestrictedGlobalGrantCheck } from 'src/hooks/useRestrictedGlobalGrantCheck';
import { useRegionsQuery } from 'src/queries/regions/regions';

import type { CreateLinodeRequest } from '@linode/api-v4';

export const PrivateIP = () => {
const { field } = useController<CreateLinodeRequest, 'private_ip'>({
name: 'private_ip',
Expand All @@ -22,7 +23,10 @@ export const PrivateIP = () => {

const regionId = useWatch<CreateLinodeRequest, 'region'>({ name: 'region' });

const selectedRegion = regions?.find((r) => r.id === regionId);
const selectedRegion = useMemo(
() => regions?.find((r) => r.id === regionId),
[regions, regionId]
);

const isEdgeRegionSelected = selectedRegion?.site_type === 'edge';

Expand Down

0 comments on commit 8a453e6

Please sign in to comment.