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

Refactor: map props to hooks #2564

Merged
merged 13 commits into from
Oct 16, 2023
Merged

Refactor: map props to hooks #2564

merged 13 commits into from
Oct 16, 2023

Conversation

katspaugh
Copy link
Member

To make our components more testable, we need to rely less on external hooks and more on props.

To this end, we're introducing a function that maps props to hooks. E.g.:

// "Dumb" component that takes props
type AddressBookTableProps = {
  chain?: ChainInfo
  setTxFlow: TxModalContextType['setTxFlow']
}

export const AddressBookTable = ({ chain, setTxFlow }: AddressBookTableProps) => {
  //...
}

// A "smart" wrapper for that component that maps additional props to hooks
export default madProps(AddressBookTable, {
  chain: useCurrentChain,
  setTxFlow: () => useContext(TxModalContext).setTxFlow,
})

With this approach, the "dumb" AddressBookTable component can be more easily tested w/o having to mock those hooks.

@github-actions
Copy link

github-actions bot commented Sep 29, 2023

Branch preview

✅ Deploy successful!

https://madprops--walletweb.review-wallet-web.5afe.dev

@github-actions
Copy link

github-actions bot commented Sep 29, 2023

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@github-actions
Copy link

github-actions bot commented Oct 16, 2023

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@katspaugh katspaugh requested a review from usame-algan October 16, 2023 09:05
@katspaugh katspaugh marked this pull request as ready for review October 16, 2023 09:17
Copy link
Member

@usame-algan usame-algan left a comment

Choose a reason for hiding this comment

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

I tried testing one of the wrapped components but get a type error when trying to render(<ExportDialog />)

src/utils/__tests__/mad-props.test.tsx Outdated Show resolved Hide resolved
src/utils/mad-props.tsx Show resolved Hide resolved
@katspaugh katspaugh merged commit 2781684 into dev Oct 16, 2023
@katspaugh katspaugh deleted the madprops branch October 16, 2023 12:29
@github-actions github-actions bot locked and limited conversation to collaborators Oct 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants