Notistack: TypeScript error when trying to use SnackbarContent component

Created on 29 Sep 2020  路  5Comments  路  Source: iamhosseindhv/notistack

I am trying to follow the custom snackbar example in the docs: https://iamhosseindhv.com/notistack/demos#custom-snackbar.
When I try and use the SnackbarContent component that is exposed by notistack, I get the following error in TypeScript:
'SnackbarContent' only refers to a type, but is being used as a value here.

Expected Behavior

SnackbarContent should of type JSX.Element

Current Behavior

Gives the TypeScript error: 'SnackbarContent' only refers to a type, but is being used as a value here.

Context

Trying to create a custom snackbar by using SnackbarContent as the root component (like in the example in the docs).

Your Environment

| Tech | Version |
|--------------|---------|
| Notistack | v1.0.0 |
| React | v16.9.0 |
| TypeScript | v3.7.2 |

Most helpful comment

Fixed in #319 . Fix will be published soon.

All 5 comments

I have the same issue.

I am trying to follow the custom snackbar example in the docs: https://iamhosseindhv.com/notistack/demos#custom-snackbar.
When I try and use the SnackbarContent component that is exposed by notistack, I get the following error in TypeScript:
'SnackbarContent' only refers to a type, but is being used as a value here.

Could you make some working domo to reproduce this issue? This code works for me.

const snackbar=useSnackbar();
.....
snackbar.enqueueSnackbar('some message',{
            variant: 'default',
                content: (key: string | number) => (
                <SidebarBanner
                    id={key}
                    header={header}
                    message={message}
                />
            ),
});

Fixed in #319 . Fix will be published soon.

I'm still experiencing this using "notistack": "^1.0.2".

import { useSnackbar, SnackbarContent } from 'notistack'; --> Module '"../../../../../node_modules/notistack/dist"' has no exported member 'SnackbarContent'.

Please provide a reproduction codesandbox. Snackbar Content is here and exported from notistack here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lsansaa picture lsansaa  路  7Comments

nebojsanb picture nebojsanb  路  3Comments

kubalobo picture kubalobo  路  5Comments

james-cordeiro picture james-cordeiro  路  6Comments

iamhosseindhv picture iamhosseindhv  路  7Comments