@usecloudstate/react-web
An optional package with sensible web default for react-core package. It provides:
- Handling authentication via a login modal.
- 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.
config
for react-core
1. Default 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);
AuthProvider
for your application
2. 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.