@8base/react-sdk 中文文档教程

发布于 3年前 浏览 25 项目主页 更新于 3年前

@8base/react-sdk

目录 使用 DocToc

Installation

npm install --save @8base/react-sdk

yarn add @8base/react-sdk

Getting Started

@8base/react 生成-sdk 提供了将 8base 与 React 结合使用的工具。

import React from 'react';
import { AppProvider, gql } from '@8base/react-sdk';
import { Auth, AUTH_STRATEGIES } from '@8base/auth';
import { Query } from 'react-apollo';

const URI = "8base API URI',

const AUTH0_CLIENT_ID = 'auth0 client ID';
const AUTH0_CLIENT_DOMAIN = 'auth0 client domain';
const REDIRECT_URI = document.location.href.replace(document.location.hash, '');

const authClient = Auth.createClient({
  strategy: AUTH_STRATEGIES.WEB_AUTH0,
  subscribable: true,
}, {
  clientId: AUTH0_CLIENT_ID,
  domain: AUTH0_CLIENT_DOMAIN,
  // Don't forget set custom domains in the authentication settings!
  redirectUri: REDIRECT_URI,
  logoutRedirectUri: REDIRECT_URI,
});

const SAMPLE_QUERY = gql`
  query UserQuery {
    user {
      id
      email
    }
  }
`;

function App() {
  return (
    <div className="App">
      <AppProvider
        uri={URI}
        authClient={authClient}
      >
        {({ loading }) => {
          if (loading) {
            return <p>Please wait...</p>;
          }
          return <Query query={ SAMPLE_QUERY }>...</Query>
        }}
      </AppProvider>
    </div>
  );
}

Examples

@8base/react-sdk

Table of Contents generated with DocToc

Installation

npm install --save @8base/react-sdk

or

yarn add @8base/react-sdk

Getting Started

@8base/react-sdk provides tools to use 8base with React.

import React from 'react';
import { AppProvider, gql } from '@8base/react-sdk';
import { Auth, AUTH_STRATEGIES } from '@8base/auth';
import { Query } from 'react-apollo';

const URI = "8base API URI',

const AUTH0_CLIENT_ID = 'auth0 client ID';
const AUTH0_CLIENT_DOMAIN = 'auth0 client domain';
const REDIRECT_URI = document.location.href.replace(document.location.hash, '');

const authClient = Auth.createClient({
  strategy: AUTH_STRATEGIES.WEB_AUTH0,
  subscribable: true,
}, {
  clientId: AUTH0_CLIENT_ID,
  domain: AUTH0_CLIENT_DOMAIN,
  // Don't forget set custom domains in the authentication settings!
  redirectUri: REDIRECT_URI,
  logoutRedirectUri: REDIRECT_URI,
});

const SAMPLE_QUERY = gql`
  query UserQuery {
    user {
      id
      email
    }
  }
`;

function App() {
  return (
    <div className="App">
      <AppProvider
        uri={URI}
        authClient={authClient}
      >
        {({ loading }) => {
          if (loading) {
            return <p>Please wait...</p>;
          }
          return <Query query={ SAMPLE_QUERY }>...</Query>
        }}
      </AppProvider>
    </div>
  );
}

Examples

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文