【发布时间】:2021-10-09 19:19:01
【问题描述】:
我正在尝试在基于 Expo/react 原生组件的类中实现 Google 身份验证,但 Expo 给出的示例是针对功能组件的。
他们使用此代码进行 Google 身份验证:
import * as React from 'react';
import * as WebBrowser from 'expo-web-browser';
import * as Google from 'expo-auth-session/providers/google';
import { Button } from 'react-native';
WebBrowser.maybeCompleteAuthSession();
export default function App() {
const [request, response, promptAsync] = Google.useAuthRequest({
expoClientId: 'GOOGLE_GUID.apps.googleusercontent.com',
iosClientId: 'GOOGLE_GUID.apps.googleusercontent.com',
androidClientId: 'GOOGLE_GUID.apps.googleusercontent.com',
webClientId: 'GOOGLE_GUID.apps.googleusercontent.com',
});
React.useEffect(() => {
if (response?.type === 'success') {
const { authentication } = response;
}
}, [response]);
return (
<Button
disabled={!request}
title="Login"
onPress={() => {
promptAsync();
}}
/>
);
}
我的问题是如何为基于类的组件做类似的事情 (export default class App extends Component)
【问题讨论】:
标签: javascript reactjs react-native expo google-authentication