Skip to content

Commit

Permalink
fix(Internal): ensure usePropsWithContext will use context regardless
Browse files Browse the repository at this point in the history
While default props are listed, with functional components and TS we do not need to list all anymore just to ensure that we use the context. So with this PR we use the context as long as the prop is not set.
  • Loading branch information
tujoworker committed Feb 23, 2022
1 parent a2ef6fb commit 0a7e9c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('usePropsWithContext', () => {
prop2: 'prop2',
a: 'a',
b: 'b',
// c: 'c', // but not c
c: 'c',
})
})

Expand Down
8 changes: 2 additions & 6 deletions packages/dnb-eufemia/src/shared/hooks/usePropsWithContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ function usePropsWithContext<Props>(
return {
...props,
...Object.entries(context).reduce((acc, [key, value]) => {
if (
// check if a prop of the same name exists
typeof props[key] !== 'undefined' &&
// and if it was NOT defined as a component prop, because its still the same as the defaults
props[key] === defaults[key]
) {
// if it was NOT defined as a component prop, because its still the same as the defaults
if (props[key] === defaults[key]) {
// then we use the context value
acc[key] = value
}
Expand Down

0 comments on commit 0a7e9c6

Please sign in to comment.