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

When using useToast(), it exits and the next line is not run.
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.
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.