Skip to content

Commit

Permalink
feat: confilct 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
SeieunYoo committed Nov 24, 2024
2 parents 6d5942d + bcc0eee commit 5757b43
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-cheetahs-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wowds-ui": patch
---

Table 컴포넌트의 context 문제를 해결해요
5 changes: 0 additions & 5 deletions .changeset/odd-baboons-hide.md

This file was deleted.

5 changes: 5 additions & 0 deletions apps/wow-docs/app/constants/routePath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const routePath = {
overview: "/overview",
foundation: "/foundation",
component: "/component",
};
6 changes: 6 additions & 0 deletions packages/wow-icons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# wowds-icons

## 0.1.6

### Patch Changes

- 6e86da8: Home, Folder 컴포넌트를 추가합니다.

## 0.1.5

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/wow-icons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wowds-icons",
"version": "0.1.5",
"version": "0.1.6",
"description": "",
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions packages/wow-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# wowds-ui

## 0.1.20

### Patch Changes

- Updated dependencies [6e86da8]
- [email protected]

## 0.1.19

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/wow-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wowds-ui",
"version": "0.1.19",
"version": "0.1.20",
"description": "",
"author": "gdsc-hongik",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/wow-ui/src/components/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const Primary: Story = {
<Table.Tbody>
{data.map(({ name, studyId, id }) => {
return (
<Table.Tr key={id} value={id}>
<Table.Tr key={id}>
<Table.Td>{name}</Table.Td>
<Table.Td>{studyId}</Table.Td>
</Table.Tr>
Expand Down
14 changes: 11 additions & 3 deletions packages/wow-ui/src/components/Table/TableContext.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { Dispatch } from "react";
import { createContext } from "react";
import { createContext, useContext } from "react";

import type { TableProps } from "@/components/Table/Table";
import useSafeContext from "@/hooks/useSafeContext";
import type useTableCheckState from "@/hooks/useTableCheckState";

export const TableContext = createContext<
Expand All @@ -15,7 +14,16 @@ export const TableContext = createContext<
>(null);

export const useTableContext = () => {
const context = useSafeContext(TableContext);
const context = useContext(TableContext);
if (!context)
return {
selectedRows: new Set<number>(),
showCheckbox: false,
rowValues: new Set<number>(),
handleRowCheckboxChange: () => {},
handleHeaderCheckboxChange: () => {},
setRowValues: () => {},
};
return context;
};

Expand Down
14 changes: 10 additions & 4 deletions packages/wow-ui/src/components/Table/Td.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { cva } from "@styled-system/css";
import { styled } from "@styled-system/jsx";
import type { CSSProperties, PropsWithChildren, Ref } from "react";
import { forwardRef } from "react";
import { forwardRef, useContext, useEffect, useState } from "react";

import {
TableCheckedContext,
useTableContext,
} from "@/components/Table/TableContext";
import useSafeContext from "@/hooks/useSafeContext";

interface TableCellProps extends PropsWithChildren {
style?: CSSProperties;
Expand All @@ -18,8 +17,15 @@ const Td = forwardRef(
(props: TableCellProps, ref: Ref<HTMLTableCellElement>) => {
const { children, ...rest } = props;
const { selectedRows } = useTableContext();
const rowValue = useSafeContext(TableCheckedContext);
const isSelected = selectedRows.has(rowValue);
const [isSelected, setIsSelected] = useState(false);

const rowValue = useContext(TableCheckedContext);
useEffect(() => {
if (rowValue) {
const value = selectedRows.has(rowValue);
setIsSelected(value);
}
}, [rowValue, selectedRows]);

return (
<styled.td
Expand Down

0 comments on commit 5757b43

Please sign in to comment.