Skip to content

Commit

Permalink
refactor: don't mutate props
Browse files Browse the repository at this point in the history
  • Loading branch information
OldStarchy committed Aug 17, 2024
1 parent cd28d0f commit e646c48
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/form/SelectCardForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {useEffect, useState} from 'react';
import {Card} from '../../context/universe/Card';
import {Button} from '../common/Button';
import {Select} from '../common/Select';
import { useEffect, useMemo, useState } from 'react';
import { Card } from '../../context/universe/Card';
import { Button } from '../common/Button';
import { Select } from '../common/Select';

export function SelectCardForm({
options,
Expand All @@ -13,7 +13,10 @@ export function SelectCardForm({
onSelectCard: (card: Card['name']) => void;
}) {
const [cardName, setCardName] = useState(options[0]);
const orderedOptions = options.sort((a, b) => a.localeCompare(b));
const orderedOptions = useMemo(
() => [...options].sort((a, b) => a.localeCompare(b)),
[options],
);

useEffect(() => {
if (options.length === 0) {
Expand Down

0 comments on commit e646c48

Please sign in to comment.