I have a SnackBar.ts file as below
import { useSnackbar } from 'notistack'; const SnackBar = (message:string, isError?:boolean) => { const { enqueueSnackbar } = useSnackbar(); return enqueueSnackbar(message, { anchorOrigin: { horizontal: 'right', vertical: 'top' }, variant: isError ? 'error' : 'success', style: { whiteSpace: 'pre-line' } }); }; export default SnackBar; So I started use that in my compoonent like below
import { SnackBar } from '../../snackbar'; const mySnack = SnackBar; useEffect(() => { console.log('error'); if (!loading && submitForm) { if (!error) { mySnack('user updated'); } else { mySnack(error, true); } } }, [error, loading, submitForm]); I'm getting this error "Error: Invalid hook call. Hooks can only be called inside of the body of a function component"
All I wanted to do is use that enqueueSnackbar as a shared method. How can I do that in typescript ?
没有评论:
发表评论