我想要一个函数,在用户刷新页面之前向服务器发送请求(不关心响应)。
我试过使用这种componentWillUnmount
方法,但页面刷新没有调用这个函数。例如
import React, { useEffect } from 'react';
const ComponentExample => () => {
useEffect(() => {
return () => {
// componentWillUnmount in functional component.
// Anything in here is fired on component unmount.
// Call my server to do some work
}
}, []) }
有没有人有任何想法如何做到这一点?