@@ -2,7 +2,7 @@ import React, { Component } from 'react';
2
2
import { createPortal } from 'react-dom' ;
3
3
import clsx from 'clsx' ;
4
4
import SnackbarContext from './SnackbarContext' ;
5
- import { MESSAGES , REASONS , originKeyExtractor , omitContainerKeys , merge , DEFAULTS } from './utils/constants' ;
5
+ import { MESSAGES , REASONS , originKeyExtractor , omitContainerKeys , merge , DEFAULTS , isDefined } from './utils/constants' ;
6
6
import SnackbarItem from './SnackbarItem' ;
7
7
import SnackbarContainer from './SnackbarContainer' ;
8
8
import warning from './utils/warning' ;
@@ -49,7 +49,7 @@ class SnackbarProvider extends Component<SnackbarProviderProps, State> {
49
49
* Returns generated or user defined key referencing the new snackbar or null
50
50
*/
51
51
enqueueSnackbar = ( message : SnackbarMessage , { key, preventDuplicate, ...options } : OptionsObject = { } ) : SnackbarKey => {
52
- const hasSpecifiedKey = key || key === 0 ;
52
+ const hasSpecifiedKey = isDefined ( key ) ;
53
53
const id = hasSpecifiedKey ? ( key as SnackbarKey ) : new Date ( ) . getTime ( ) + Math . random ( ) ;
54
54
55
55
const merger = merge ( options , this . props , DEFAULTS ) ;
@@ -173,7 +173,7 @@ class SnackbarProvider extends Component<SnackbarProviderProps, State> {
173
173
* Set the entered state of the snackbar with the given key.
174
174
*/
175
175
handleEnteredSnack : TransitionHandlerProps [ 'onEntered' ] = ( node , isAppearing , key ) => {
176
- if ( typeof key === 'undefined' ) {
176
+ if ( ! isDefined ( key ) ) {
177
177
throw new Error ( 'handleEnteredSnack Cannot be called with undefined key' ) ;
178
178
}
179
179
@@ -215,7 +215,7 @@ class SnackbarProvider extends Component<SnackbarProviderProps, State> {
215
215
closeSnackbar : ProviderContext [ 'closeSnackbar' ] = ( key ) => {
216
216
// call individual snackbar onClose callback passed through options parameter
217
217
const toBeClosed = this . state . snacks . find ( item => item . key === key ) ;
218
- if ( key && toBeClosed && toBeClosed . onClose ) {
218
+ if ( isDefined ( key ) && toBeClosed && toBeClosed . onClose ) {
219
219
toBeClosed . onClose ( null , REASONS . INSTRUCTED , key ) ;
220
220
}
221
221
@@ -232,7 +232,7 @@ class SnackbarProvider extends Component<SnackbarProviderProps, State> {
232
232
// @ts -ignore
233
233
handleExitedSnack : TransitionHandlerProps [ 'onExited' ] = ( event , key1 , key2 ) => {
234
234
const key = key1 || key2 ;
235
- if ( typeof key === 'undefined' ) {
235
+ if ( ! isDefined ( key ) ) {
236
236
throw new Error ( 'handleExitedSnack Cannot be called with undefined key' ) ;
237
237
}
238
238
0 commit comments