@usecloudstate/react-web
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

@usecloudstate/react-web

An optional package with sensible web default for react-core package. It provides:

  1. Handling authentication via a login modal.
  2. Handling authentication callbacks automatically.

Installation

You can install the package with:

npm install @usecloudstate/react-web

Usage

This package is to be a supplementary package for the @usecloudstate/react-core package.

1. Default config for react-core

To use this package, you must provide the configs it exposes to your CloudState client initialization.

// src/util/cloudState.js
import { CloudStateClient } from '@usecloudstate/react-core';
import { config } from '@usecloudstate/react-web';

export const cloudState = new CloudStateClient("<YOUR APP ID>", config);

2. AuthProvider for your application

AuthProvider will trigger the login modal when a request to the server is unauthenticated.

// src/App.js

import React from "react";
import { state } from "./utils/cloudState";

function App() {
  return (
    <div className="App">
      { /* Initialize the AuthProvider with the cloudState client */ }
      <AuthProvider client={state} />
      <header className="App-header"></header>
      <main>
        <h1>Welcome to React</h1>
      </main>
    </div>
  );
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @usecloudstate/react-web

Weekly Downloads

9

Version

2.0.3

License

MIT

Unpacked Size

32.4 kB

Total Files

23

Last publish

Collaborators

  • ncthis