javascript - 使用打字稿时react-google-login中的注销挂钩问题
问题描述
我对 onLogoutSuccess 有问题:
const onLogoutSuccess = (res: any) =>{
alert('Logout successfully');
}
const { signOut } = useGoogleLogout({
clientId,
onLogoutSuccess,
onFailure
})
我得到错误:
(property) UseGoogleLogoutProps.onLogoutSuccess?: (() => void) | undefined
Type '(res: any) => void' is not assignable to type '() => void'.ts(2322)
index.d.ts(136, 12): The expected type comes from property 'onLogoutSuccess' which is declared here on type 'UseGoogleLogoutProps'
解决方案
我已经解决了这个问题,请看看我希望它对你的目标有所帮助。
JS代码
const onLogoutSuccess = () => {
console.log('logout');
history.push('/');
};
const onFailure = () => {
console.log('logout fail');
};
const { signOut } = useGoogleLogout({
clientId: GOOGLE_CLIENT_ID,
onLogoutSuccess: onLogoutSuccess,
onFailure: onFailure,
});
html
<button onClick={signOut}>Log Out</button>
推荐阅读
- html - 我如何在列表之间放置一个段落?
- vue.js - 将道具传递给设置了 v-if 的组件
- java - 为什么在生产服务器上发生了 CouldNotLockPageException 而不是在本地系统上?
- django - 如何在 django 中计算类别内的产品数量
- javascript - 如何将nodejs后端连接到前端?
- javascript - 预加载文件夹及其所有子文件夹中的所有图像
- winapi - 使用 IOCTL_VIDEO_QUERY_AVAIL_MODES 获取视频适配器支持的模式列表
- for-loop - 使用 step0 和 step1 与结果子步骤停止循环 python
- tkinter - Tkinter 错误,_tkinter.TclError:无法删除 Tcl 命令
- javascript - 如何在我的 Highlight.js 中添加更多语言