-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[docs] Polish Snackbar demos #15129
[docs] Polish Snackbar demos #15129
Conversation
No bundle size changes comparing 2482d2b...0522726 |
@@ -74,7 +70,7 @@ class ConsecutiveSnackbars extends React.Component<Props, State> { | |||
|
|||
render() { | |||
const { classes } = this.props; | |||
const { messageInfo = {} as SnackbarMessage } = this.state; | |||
const { messageInfo = {} as Partial<SnackbarMessage> } = this.state; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was an unsafe cast. It allowed messageInfo.message.length
while it might throw at runtime if the queue is empty.
@@ -27,6 +23,10 @@ class App extends React.Component<withSnackbarProps> { | |||
} | |||
} | |||
|
|||
(App as React.ComponentClass<withSnackbarProps>).propTypes = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite ugly but it's the pattern we use throughout the codebase. Allows separation of interface and implementation and doesn't block readability (usually what we're interested in first is render
).
}; | ||
} | ||
class DirectionSnackbar extends React.Component<{}, State> { | ||
state: State = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generic argument in React.Component
is required for correct setState
type while the explicit annotation in the class field is required for correct types in this.state
. Otherwise TypeScript will infer the apparent type ({ open: boolean }
) which means this.state.Transition
is access of a not existing key.
Removes some unnecessary JS diffs created in #15087.