Skip to content

Commit

Permalink
Merge pull request #1306 from dnbexperience/fix/use-props-with-context
Browse files Browse the repository at this point in the history
fix(Internal): ensure usePropsWithContext will use context regardless
  • Loading branch information
tujoworker authored Feb 23, 2022
2 parents a2ef6fb + 0a7e9c6 commit 3d6ee2d
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 3d6ee2d

Please sign in to comment.