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

Implement custom createContext util function #1442

Merged
merged 12 commits into from
Jul 4, 2023

Conversation

sungik-choi
Copy link
Contributor

@sungik-choi sungik-choi commented Jun 23, 2023

Self Checklist

  • I wrote a PR title in English.
  • I added an appropriate label to the PR.
  • I wrote a commit message in English.
  • I wrote a commit message according to the Conventional Commits specification.
  • I added the appropriate changeset for the changes.
  • [Component] I wrote a unit test about the implementation.
  • [Component] I wrote a storybook document about the implementation.
  • [Component] I tested the implementation in various browsers.
    • Windows: Chrome, Edge, (Optional) Firefox
    • macOS: Chrome, Edge, Safari, (Optional) Firefox
  • [New Component] I added my username to the correct directory in the CODEOWNERS file.

Related Issue

Fixes #1354

Summary

Context Provider와 useContext hook을 적은 코드로 쉽게 사용할 수 있게 해주는 커스텀 유틸 함수를 구현하고, 기존 코드를 교체합니다.

Details

  • context value로 undefinednull 을 구분합니다. 기존 FormControl 같은 케이스를 커버하기 위해 null 일 경우에만 에러를 던지도록 구현했습니다.
  • 자세한 내용은 이슈 참고 부탁드립니다.

Breaking change or not (Yes/No)

No, 동작 변경은 없어야 함.

References

@sungik-choi sungik-choi added the refactoring Issue or PR related to refactoring with no functional changes label Jun 23, 2023
@sungik-choi sungik-choi self-assigned this Jun 23, 2023
@changeset-bot
Copy link

changeset-bot bot commented Jun 23, 2023

⚠️ No Changeset found

Latest commit: d91d86f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -4,3 +4,44 @@ export const getReactVersion = () => {
const [major, minor, patch] = React.version.split('.').map(Number)
return { major, minor, patch }
}

type NonNullableValue = object | number | string | boolean | bigint | symbol
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See: https://www.typescriptlang.org/docs/handbook/basic-types.html#object

object is a type that represents the non-primitive type, i.e. anything that is not number, string, boolean, bigint, symbol, null, or undefined.

undefined, null 을 제외한 모든 타입 (primitive / reference)

Comment on lines +36 to +38
if (contextValue === null) {
throw new Error(`'${consumerName}' must be used within '${providerName}'`)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꼭 특정 컨텍스트 아래에서만 사용해야하는 경우, 기본값에 null 을 지정하여 컨텍스트가 없을 경우 에러를 던지도록 합니다.

@codecov
Copy link

codecov bot commented Jun 23, 2023

Codecov Report

Patch coverage: 89.28% and project coverage change: +0.07 🎉

Comparison is base (bb196f1) 87.16% compared to head (d91d86f) 87.23%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1442      +/-   ##
==========================================
+ Coverage   87.16%   87.23%   +0.07%     
==========================================
  Files         279      277       -2     
  Lines        3872     3862      -10     
  Branches      810      809       -1     
==========================================
- Hits         3375     3369       -6     
+ Misses        424      420       -4     
  Partials       73       73              
Impacted Files Coverage Δ
...ackages/bezier-react/src/components/Forms/index.ts 71.42% <ø> (+4.76%) ⬆️
...bezier-react/src/components/Modals/Modal/Modal.tsx 100.00% <ø> (ø)
...r-react/src/components/Modals/Modal/Modal.types.ts 100.00% <ø> (ø)
.../bezier-react/src/components/Toast/ToastContext.ts 0.00% <0.00%> (ø)
...ezier-react/src/components/Toast/ToastProvider.tsx 0.00% <ø> (ø)
...ages/bezier-react/src/components/Toast/useToast.ts 0.00% <0.00%> (ø)
...kages/bezier-react/src/components/Tooltip/index.ts 100.00% <ø> (ø)
packages/bezier-react/src/utils/reactUtils.ts 81.81% <71.42%> (-18.19%) ⬇️
...t/src/components/OutlineItem/OutlineItemContext.ts 78.57% <87.50%> (-1.43%) ⬇️
...t/src/components/Forms/FormControl/FormControl.tsx 95.91% <100.00%> (ø)
... and 17 more

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@github-actions
Copy link
Contributor

Chromatic Report

🚀 Congratulations! Your build was successful!

@sungik-choi sungik-choi merged commit ded3f4e into channel-io:main Jul 4, 2023
@sungik-choi sungik-choi deleted the feat/create-context branch July 4, 2023 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Issue or PR related to refactoring with no functional changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the createContext hook
1 participant