Chakra-ui: useToast() function terminated

Created on 21 Sep 2019  路  3Comments  路  Source: chakra-ui/chakra-ui

The function terminated when I add the line const toast = useToast();, as showed in this image:

8FAA166C-F342-4CE6-B92E-EE9061A13F08.png

When using useToast(), it exits and the next line is not run.

Most helpful comment

Yes, it seems you can't use hooks in Class components: https://reactjs.org/docs/hooks-faq.html#should-i-use-hooks-classes-or-a-mix-of-both

I found this article that shows how to use hooks in Class components via render prop: https://infinum.co/the-capsized-eight/how-to-use-react-hooks-in-class-components.

All 3 comments

It seems to happen because I break the rules of react hooks. How can I use useToast in non-hook environments? I'm not ready to use react hooks right now...

Yes, it seems you can't use hooks in Class components: https://reactjs.org/docs/hooks-faq.html#should-i-use-hooks-classes-or-a-mix-of-both

I found this article that shows how to use hooks in Class components via render prop: https://infinum.co/the-capsized-eight/how-to-use-react-hooks-in-class-components.

Yes, it seems you can't use hooks in Class components: https://reactjs.org/docs/hooks-faq.html#should-i-use-hooks-classes-or-a-mix-of-both

I found this article that shows how to use hooks in Class components via render prop: https://infinum.co/the-capsized-eight/how-to-use-react-hooks-in-class-components.

Thanks a lot. That's the key point. I will also try to learn React Hooks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sumdook picture sumdook  路  3Comments

nainardev picture nainardev  路  3Comments

checkmatez picture checkmatez  路  3Comments

Calvein picture Calvein  路  3Comments

kripod picture kripod  路  3Comments