【问题标题】:How to do Expo/react-native Google Authentication in a class based component?如何在基于类的组件中进行 Expo/react-native Google 身份验证?
【发布时间】: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


    【解决方案1】:

    这其实是一个笼统的主题,如何从类组件中调用React的功能组件。

    特定于谷歌登录,这个答案可以提供帮助:https://stackoverflow.com/a/66974167/1870873

    【讨论】:

    • 不幸的是,这似乎是唯一的方式
    猜你喜欢
    • 2023-02-14
    • 2021-11-30
    • 1970-01-01
    • 2021-01-03
    • 2023-03-30
    • 2021-10-31
    • 2020-12-20
    • 2015-08-12
    • 1970-01-01
    相关资源
    最近更新 更多