Skip to content

Commit

Permalink
perf(app-board): remove style recalculation spike
Browse files Browse the repository at this point in the history
  • Loading branch information
rams23 committed Feb 5, 2021
1 parent 9c01382 commit ab8019f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 0 additions & 3 deletions packages/game-app/src/_shared/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ const CardComponent: React.FC<CardProps> = ({
return (
<CardWrapper dragging={dragging} bigger={bigger}>
<CardHeader type={type}>
<PatternContainer>
<PipePattern />
</PatternContainer>
<CardHeading>{type}</CardHeading>
<CardHeadingTags>
{tags?.map(t => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ const ConnectedCard: React.FC<Props> = ({ id, dragging, bigger }) => {

ConnectedCard.displayName = 'ConnectedCard';

export default ConnectedCard;
export default React.memo(ConnectedCard);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useDraggable } from '@dnd-kit/core';
import { useDispatch, useSelector } from 'react-redux';
import { actions, selectors } from '../../slice';
Expand Down Expand Up @@ -79,18 +79,30 @@ const DraggableCard: React.FC<Props> = ({ id, bigger }) => {
}
}, [heldBySomeoneElse, animating]);

const card = useMemo(() => {
return <ConnectedCard bigger={bigger} id={id} />;
}, [bigger, id]);

const estimations = useMemo(() => {
return (
<>
{estimationOpen && <EstimationEditor saveEstimation={saveEstimation} initialEstimation={estimation} />}
{!estimationOpen && estimation && <EstimationInCard moving={isCardMoving} estimation={estimation} />}
</>
);
}, [estimation, estimationOpen, isCardMoving, saveEstimation]);

return (
<div style={style} data-cy={`card-${id}`}>
{estimationOpen && <EstimationEditor saveEstimation={saveEstimation} initialEstimation={estimation} />}
{!estimationOpen && estimation && <EstimationInCard moving={isCardMoving} estimation={estimation} />}
{estimations}
<CardWrapper
ref={setNodeRef}
{...listeners}
onPointerDown={onPointerDown}
{...attributes}
isDragging={isCardMoving}
>
<ConnectedCard bigger={bigger} id={id} />
{card}
</CardWrapper>
</div>
);
Expand Down

0 comments on commit ab8019f

Please sign in to comment.