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

perf: tag list에 memo를 사용하여 최적화를 적용하라 #613

Merged
merged 1 commit into from
Feb 9, 2023
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
4 changes: 2 additions & 2 deletions src/components/common/EmptyStateArea.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memo, ReactElement } from 'react';
import { ReactElement } from 'react';

import styled from '@emotion/styled';

Expand Down Expand Up @@ -46,7 +46,7 @@ function EmptyStateArea({
);
}

export default memo(EmptyStateArea);
export default EmptyStateArea;

const EmptyStateWrapper = styled.section<{ marginTop: string; }>`
display: flex;
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/ProfileImage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactElement } from 'react';
import { memo, ReactElement } from 'react';

import Image from 'next/image';

Expand Down Expand Up @@ -50,7 +50,7 @@ function ProfileImage({
);
}

export default ProfileImage;
export default memo(ProfileImage);

const ProfileAvatarImage = styled(Image)`
border-radius: 70%;
Expand Down
24 changes: 13 additions & 11 deletions src/components/common/SwitchButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ interface Props {
defaultChecked: boolean;
}

const SwitchButton = ({ onChange, defaultChecked }: Props) => (
<SwitchButtonWrapper
name="switch-toggle"
defaultChecked={defaultChecked}
title="switchButton"
aria-label="No label tag"
onChange={onChange}
icons={false}
data-testid="switch-button"
/>
);
function SwitchButton({ onChange, defaultChecked }: Props) {
return (
<SwitchButtonWrapper
name="switch-toggle"
defaultChecked={defaultChecked}
title="switchButton"
aria-label="No label tag"
onChange={onChange}
icons={false}
data-testid="switch-button"
/>
);
}

export default SwitchButton;

Expand Down
4 changes: 2 additions & 2 deletions src/components/common/Tag.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactElement } from 'react';
import { memo, ReactElement } from 'react';
import { X as CloseSvg } from 'react-feather';

import { useTheme } from '@emotion/react';
Expand Down Expand Up @@ -37,7 +37,7 @@ function Tag({ tag, onRemove, onClick }: Props): ReactElement {
);
}

export default Tag;
export default memo(Tag);

const TagWrapper = styled.div`
display: inline-flex;
Expand Down
14 changes: 8 additions & 6 deletions src/components/home/TagsBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactElement } from 'react';
import { memo, ReactElement, useCallback } from 'react';

import styled from '@emotion/styled';
import { useSetRecoilState } from 'recoil';
Expand All @@ -13,23 +13,25 @@ function TagsBar(): ReactElement {

const setGroupsCondition = useSetRecoilState(groupsConditionState);

const onClick = useCallback((name: string) => setGroupsCondition((prev) => ({
...prev,
tag: name,
})), []);

return (
<TagsWrapper>
{tags.map(({ name }) => (
<Tag
key={name}
tag={name}
onClick={() => setGroupsCondition((prev) => ({
...prev,
tag: name,
}))}
onClick={() => onClick(name)}
/>
))}
</TagsWrapper>
);
}

export default TagsBar;
export default memo(TagsBar);

const TagsWrapper = styled.div`
height: 36px;
Expand Down
4 changes: 2 additions & 2 deletions src/components/write/TagForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ function TagForm({ tags: initialTags, onChange }: Props): ReactElement {
actionKeyEvent(e, ['Enter']);
}, [actionKeyEvent]);

const handleRemove = (nextTags: string[]) => {
const handleRemove = useCallback((nextTags: string[]) => {
setTags(nextTags);
onChange(nextTags);
};
}, [onChange]);

useEffect(() => {
setTags(initialTags);
Expand Down
8 changes: 4 additions & 4 deletions src/components/write/TagList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactElement } from 'react';
import { memo, ReactElement, useCallback } from 'react';

import Tag from '../common/Tag';

Expand All @@ -8,11 +8,11 @@ interface Props {
}

function TagList({ onRemove, tags }: Props): ReactElement {
const handleRemove = (target: string) => {
const handleRemove = useCallback((target: string) => {
const nextTags = tags.filter((tag) => tag !== target);

onRemove(nextTags);
};
}, [tags, onRemove]);

return (
<>
Expand All @@ -27,4 +27,4 @@ function TagList({ onRemove, tags }: Props): ReactElement {
);
}

export default TagList;
export default memo(TagList);
2 changes: 1 addition & 1 deletion src/containers/write/WriteFormContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function WriteFormContainer(): ReactElement | null {

const onChangeFields = useCallback((form: Partial<WriteFields>) => {
changeFields((prevState) => ({ ...prevState, ...form }));
}, [changeFields]);
}, []);

if (!user) {
return null;
Expand Down