Skip to content

Commit

Permalink
perf: 타입스크립트 성능 개선 적용 (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
saseungmin authored Oct 9, 2024
1 parent 659b48d commit 36d4fd5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
28 changes: 17 additions & 11 deletions apps/web/src/components/atoms/ScrollElement/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
'use client';

import {
createElement, JSX, useEffect, useRef,
ComponentProps,
createElement,
ElementType,
useEffect,
useRef,
} from 'react';

import clsx from 'clsx';

import styles from './index.module.scss';

type Props<ElementType extends keyof JSX.IntrinsicElements> =
JSX.IntrinsicElements[ElementType] & {
elementType?: keyof JSX.IntrinsicElements;
activeParam: string;
targetParam?: string;
scrollIntoViewOptions?: ScrollIntoViewOptions;
};
type ScrollElementProps<E extends ElementType> = {
elementType?: E;
activeParam: string;
targetParam?: string;
scrollIntoViewOptions?: ScrollIntoViewOptions;
};

function ScrollElement<E extends keyof JSX.IntrinsicElements>({
elementType = 'div', activeParam, children, className, targetParam, scrollIntoViewOptions, ...props
type Props<E extends ElementType> =
ScrollElementProps<E> & Omit<ComponentProps<E>, keyof ScrollElementProps<E>>;

function ScrollElement<E extends ElementType>({
elementType, activeParam, children, className, targetParam, scrollIntoViewOptions, ...props
}: Props<E>) {
const containerRef = useRef<Element>(null);

Expand All @@ -29,7 +35,7 @@ function ScrollElement<E extends keyof JSX.IntrinsicElements>({

return (
createElement(
elementType,
elementType || 'div',
{
...props,
ref: containerRef,
Expand Down
18 changes: 11 additions & 7 deletions apps/web/src/components/molecules/LinkConverter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { createElement, Fragment, JSX } from 'react';
import {
ComponentProps, createElement, ElementType, Fragment,
} from 'react';

import ExternalLink from '@/components/atoms/ExternalLink';

import styles from './index.module.scss';

type Props<ElementType extends keyof JSX.IntrinsicElements> =
JSX.IntrinsicElements[ElementType] & {
elementType?: keyof JSX.IntrinsicElements;
type LinkConverterProps<E extends ElementType> = {
elementType?: E;
className?: string;
text: string;
};

function LinkConverter<E extends keyof JSX.IntrinsicElements>({
className, text, elementType = 'div', ...props
type Props<E extends ElementType> =
LinkConverterProps<E> & Omit<ComponentProps<E>, keyof LinkConverterProps<E>>;

function LinkConverter<E extends ElementType>({
className, text, elementType, ...props
}: Props<E>) {
const urlRegex = /(https?:\/\/[^\s]+)/g;

Expand All @@ -27,7 +31,7 @@ function LinkConverter<E extends keyof JSX.IntrinsicElements>({

return (
createElement(
elementType,
elementType || 'div',
{
...props,
className,
Expand Down

0 comments on commit 36d4fd5

Please sign in to comment.