Skip to content

Commit

Permalink
refactor(SelectBox): 컴포넌트 및 사용처에 memoization 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
Creative-Lee committed Jun 9, 2023
1 parent a69c602 commit a3aad30
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/components/@common/SelectBox/SelectBox.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { memo } from 'react';
import styled from 'styled-components';

type Options = { name: string; value: string };
Expand All @@ -20,7 +21,7 @@ const SelectBox = ({ value, options, onChange }: SelectBoxProps) => {
);
};

export default SelectBox;
export default memo(SelectBox);

const Select = styled.select`
width: 100%;
Expand Down
7 changes: 4 additions & 3 deletions src/components/Layout/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useCallback, useMemo } from 'react';
import { Link } from 'react-router-dom';
import styled from 'styled-components';

Expand All @@ -21,14 +22,14 @@ const Header = () => {
const loadableCartProducts = useRecoilValueLoadable(cartProductsState);
const cartProductCount = loadableCartProducts.state === 'loading' ? 0 : loadableCartProducts.contents.size;

const serverOwner = store.getStorage<ServerOwner>(SERVER_OWNER) ?? '헙크';
const serverOwner = useMemo(() => store.getStorage<ServerOwner>(SERVER_OWNER) ?? '헙크', []);

const handleServerOwner = (e: React.ChangeEvent<HTMLSelectElement>) => {
const handleServerOwner = useCallback((e: React.ChangeEvent<HTMLSelectElement>) => {
const value = e.target.value as ServerOwner;

store.setStorage(SERVER_OWNER, value);
window.location.reload();
};
}, []);

return (
<HeaderContainer>
Expand Down

0 comments on commit a3aad30

Please sign in to comment.