Skip to content

Instantly share code, notes, and snippets.

@nkmcheng
Last active June 29, 2022 15:03
Show Gist options
  • Save nkmcheng/74d8c07263b254a459be3e842c203301 to your computer and use it in GitHub Desktop.
Save nkmcheng/74d8c07263b254a459be3e842c203301 to your computer and use it in GitHub Desktop.
createSnackbarSlice
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