Last active
June 29, 2022 15:03
-
-
Save nkmcheng/74d8c07263b254a459be3e842c203301 to your computer and use it in GitHub Desktop.
createSnackbarSlice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { StoreSlice } from '../../shared/types'; | |
export interface ISnackbarProperty { | |
visible: boolean; | |
message: string; | |
} | |
export interface ISnarkbarSlice { | |
snackbar: ISnackbarProperty; | |
showSnackbar: (message: string) => void; | |
hideSnackbar: () => void; | |
} | |
const createSnackbarSlice: StoreSlice<ISnarkbarSlice> = (set, get) => ({ | |
snackbar: { | |
visible: false, | |
message: '' | |
}, | |
showSnackbar: (message: string) => | |
set((state) => ({ ...state, snackbar: { visible: true, message } })), | |
hideSnackbar: () => | |
set((state) => ({ ...state, snackbar: { visible: false, message: '' } })) | |
}); | |
export default createSnackbarSlice; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment