0.0.4 • Published 5 years ago

dbdbdb-provider v0.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

dbdbdb-provider

A library to more easily use dbdbdb with React.

Install

  1. Complete prerequisites
  2. Install this module npm i dbdbdb-provider --save

Usage

See demo for usage with react@next.

Basic usage:

import React from 'react';
import ReactDOM from 'react-dom';

const {
  DropboxContext,
  DropboxProvider,
} = createDropboxProvider({
  clientId: "xhb23gwddzfsp8k"
});


class MyApp extends React.Component {
  constructor(props) {
    super(props);
    this.state = { client: null };
  }
  componentDidMount() {
    const client = this.context.getClient();
    this.setState({ client });
    if (client) {
      client.usersGetCurrentAccount().then(userInfo => {
        this.setState({ userInfo });
      });
    }
  }
  render() {
    if (!this.state.client) {
      return <a href={this.context.authUrl}>Login</a>;
    }

    if (this.state.client && !this.state.userInfo) {
      return <p>Loading...</p>;
    }

    return (
      <div>
        <h2>{this.state.userInfo.name.familiar_name}</h2>
        <img
          with={50}
          height={50}
          src={this.state.userInfo.profile_photo_url}
          alt={this.state.userInfo.name.display_name}
        />
      </div>
    );
  }
}

MyApp.contextType = DropboxContext;

function App() {
  return (
    <DropboxProvider>
      <MyApp />
    </DropboxProvider>
  );
}

ReactDOM.render(<App />, document.getElementById('root'));
0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago