From 2a75041fd2145b3ee4d0c25eadbfda824ba98ace Mon Sep 17 00:00:00 2001 From: Jimmy Multani Date: Thu, 24 Oct 2019 14:45:15 -0400 Subject: [PATCH 1/2] Allow 0 as a snackbar key identifier At the moment, setting the `key` option to `0` will not respect it, and generate a random `id` based on `new Date().getTime() + Math.random()`. This fix will check if the value of `key` is `undefined` before defaulting to auto-generating the `id`. A specific use case for this would be when receiving payloads from an external source (like a subscription service), where the `id` could possibly start at `0`. --- src/SnackbarProvider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SnackbarProvider.js b/src/SnackbarProvider.js index a6dc07cd..f2943a28 100644 --- a/src/SnackbarProvider.js +++ b/src/SnackbarProvider.js @@ -57,7 +57,7 @@ class SnackbarProvider extends Component { } } - const id = key || new Date().getTime() + Math.random(); + const id = typeof key !== 'undefined' ? key : new Date().getTime() + Math.random(); const snack = { key: id, ...options, From 43884550efda8530f03e73daefd5112f2678731e Mon Sep 17 00:00:00 2001 From: Jimmy Multani Date: Thu, 24 Oct 2019 17:55:13 -0400 Subject: [PATCH 2/2] check 0 more explicitly based off feedback, would prefer to check if 0 directly, than implicit !== 'undefined' --- src/SnackbarProvider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SnackbarProvider.js b/src/SnackbarProvider.js index f2943a28..a5f4681f 100644 --- a/src/SnackbarProvider.js +++ b/src/SnackbarProvider.js @@ -57,7 +57,7 @@ class SnackbarProvider extends Component { } } - const id = typeof key !== 'undefined' ? key : new Date().getTime() + Math.random(); + const id = key || key === 0 ? key : new Date().getTime() + Math.random(); const snack = { key: id, ...options,