-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Suggestion] Extracting props of a component #63
Comments
ok this took me a while to understand but wow. super handy!!! i love it. i'm gonna break up the cheatsheet to a basic and an advanced section, give me a while |
Why not to use const defaultProps: React.ComponentProps<typeof Modal> = {
title: "Hello World",
visible: true,
onClick: jest.fn(),
}; |
you may be righ! for reference this is what we currently have https://react-typescript-cheatsheet.netlify.app/docs/advanced/patterns_by_usecase/#props-extracting-prop-types-of-a-component |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions! |
@MarcelReis that was an excellent suggestion, thank you. i found our prior existing docs too complex for the common usecase, however Ferdy above is right that there are proptypes and defualtprops edge cases to consider if you want a fully reliable solution. i've opted for linking to this issue rather than bombarding our readers with complex utils right off the bat. |
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
closes typescript-cheatsheets/react#63 thanks to @MarcelReis' suggestions.
Not sure where to put it, but I have these helper types in my team's codebase to extract the props of a component:
As far as how we use them, there's a lot of places where I want to reuse some slices of props because of prop drilling, and I can either export the props type as part of the module or I use this (either way works), the advantage of using this is that a refactor of the source of truth component will propagate to all consuming components.
I also use them to strongly type custom event handlers if they're not written at the call sites themselves (i.e. inlined with the JSX attribute):
The text was updated successfully, but these errors were encountered: