Cogoport / cogo-toast

Beautiful, Zero Configuration, Toast Messages for React. Only ~ 4kb gzip, with styles and icons
https://cogoport.github.io/cogo-toast
MIT License
673 stars 1 forks source link

Does it work for SSR ? #57

Closed bakate closed 4 years ago

bakate commented 4 years ago

I'm trying to use it with Next.js but I'm getting some errors

ReferenceError: document is not defined cogoToast C:/Users/bak/React/STRAPI/restaurant/front-end/node_modules/cogo-toast/dist/index.js:1:9823 Function.cogoToast.loading C:/Users/backa/React/STRAPI_PROJECTS/restaurant/front-end/node_modules/cogo-toast/dist/index.js:1:10779 Recipes ./components/Recipes.js:24 21 | const Recipes = () => { 22 | const { loading, error, data } = useQuery(RECIPES_QUERY); 23 | if (loading) {

24 | return cogoToast.loading('loading'); 25 | } 26 | if (error) return Error ${error.message};

anmdotdev commented 4 years ago

@bakate Thats not the current way to use the cogoToast function. It can only be triggered when React has successfully mounted in the DOM.

If you want to display the toast directly in your render, you can directly use the Toast component, instead of the cogoToast function. import { Toast } from 'cogo-toast'