如何在 React 中使用函数组件在 Dom 加载时显示 SweetAlert 弹出窗口

How to display a SweetAlert popup on Dom load using Function Component in React

我最近开始使用 React,如果这个问题太过分了,我深表歉意"noobish"。所以我试图在路径(URL)更改上有一个 SweetAlert 弹出窗口,有没有一种方法可以使用功能组件来完成?

我已经查过了 Callback when DOM is loaded in react.js 但这仅适用于 class 组件..

这可以使用 useEffect() hook

If you’re familiar with React class lifecycle methods, you can think of useEffect Hook as componentDidMount, componentDidUpdate, and componentWillUnmount combined.

因为 hooks 只能在功能组件中调用。