@8base/react-sdk 中文文档教程
@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
更多
你可能也喜欢
- @0xslime/sdk 中文文档教程
- @21epub/float-window 中文文档教程
- @21kb/react-device-orientation-hook 中文文档教程
- @3test/ethereum-http-provider 中文文档教程
- @abcpros/bitcore-lib-doge 中文文档教程
- @abcum/ember-appupdate 中文文档教程
- @acoustic-content-sdk/ng-edit 中文文档教程
- @actionishope/shelley-puma 中文文档教程
- @activatortube/springboot-and-antd-code 中文文档教程
- @activeprospect/integration-dev-webpack 中文文档教程