-
Notifications
You must be signed in to change notification settings - Fork 4.2k
How to handle default props? #4
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
Comments
yeah I get mixed messages from the community on this. I like to assign when destructuring, but others like to use defaultProps. want to put in a PR? |
Putting this as a comment but willing to propose a PR if @rssfrncs is not taking this. interface IMyComponentProps {
firstProp: string;
secondProp: IPerson[];
}
export class MyComponent extends React.Component<IMyComponentProps, {}> {
static defaultProps: Partial<IMyComponentProps> = {
firstProp: "default",
};
} |
I dont use defaultProps myself but just wanted to add that the Spectrum community also suggested adding a also, here is a slightly longer approach also using Omit: https://levelup.gitconnected.com/ultimate-react-component-patterns-with-typescript-2-8-82990c516935 Yours seem much simpler! would love a PR here, this is the top requested info based on feedback from reddit/hn/twitter/spectrum |
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion #4
@Attrash-Islam go ahead with a PR buddy! |
@rssfrncs Thanks! I will do it tomorrow after reviewing the whole repository so it match the README with the other section in the same format 😉 |
Have you checked out this similar repo? It has an interesting approach to default props. Whilst it is focused on Redux React apps there is a lot of overlap. |
The way they do it is not that good since you need to update your DefaultProps interface every time you want to include additional prop (see how My suggestion is using |
[defaultProps] - Related to "How to handle default props?" #4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
add nitpicks from clutchhunter https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e01d2md/?context=3 add defaultprops discussion typescript-cheatsheets/react#4
Would be great to have a section detailing the different approaches to handling default props.
The text was updated successfully, but these errors were encountered: