# react-provider-maker

> A simple library to make react providers

Latest version **1.0.6** (published 2020-07-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-provider-maker
pnpm add react-provider-maker
yarn add react-provider-maker
bun add react-provider-maker
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2020-07-12 |
| First published | 2020-05-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Victor Nicolas Lizarraga Ochoa |
| Maintainers | victorlizarraga |
| Keywords | reactjs, react, providers, maker |

## Links

- npm: https://www.npmjs.com/package/react-provider-maker
- Repository: https://github.com/VictorNicolasLO/react-provider-maker
- Homepage: https://github.com/VictorNicolasLO/react-provider-maker#readme
- Issues: https://github.com/VictorNicolasLO/react-provider-maker/issues
- npm.io page: https://npm.io/package/react-provider-maker

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2020-07-12
- 1.0.5 — 2020-07-12
- 1.0.4 — 2020-05-23
- 1.0.3 — 2020-05-23
- 1.0.2 — 2020-05-12
- 1.0.1 — 2020-05-12
- 1.0.0 — 2020-05-12

## README

# React provider maker

Share hooks between any component in your app!

## How to use it

**Install**

```bash
npm install react-provider-maker
or
yarn add react-provider-maker
```

**creating the provider!**

```typescript
// auth-provider.ts
import { makeProvider } from "../lib";
import { useState, useCallback } from "react";

// Hook with any logic you want to share
function useAuth() {
  const [isAuth, setAuth] = useState(false);
  const login = useCallback((user, password) => {
    // validate login
    if (user && password) {
      setAuth(true);
    }
  }, []);
  return { isAuth, login };
}

// Creating provider and exporting its Provider to implemented and its hook to use it
export const {
  Provider: AuthProvider,
  useProvider: useAuthProvider,
} = makeProvider(useAuth);
```

**Initializing in your app**

```tsx
// app.tsx
import * as React from "react";
import { AuthProvider } from "./auth-provider";
import LoginForm from "./login-form";

function App() {
  return (
    <AuthProvider>
      <LoginForm />
    </AuthProvider>
  );
}

export default App;
```

**Using it in any component inside your app**

```tsx
// auth-provider.tsx
import * as React from "react";
import { useAuthProvider } from "./auth-provider";

function LoginForm() {
  const { isAuth, login } = useAuthProvider();
  return isAuth ? (
    <div>loged in</div>
  ) : (
    <div onClick={() => login("user", "password")}>click to login</div>
  );
}

export default LoginForm;
```

---
_Source: https://npm.io/package/react-provider-maker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
