# react-cookies-users-provider

> Provides the logged in user after saving them in a cookie

Latest version **1.0.4** (published 2020-04-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-cookies-users-provider
pnpm add react-cookies-users-provider
yarn add react-cookies-users-provider
bun add react-cookies-users-provider
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-04-17 |
| First published | 2020-04-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 2 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Redvanisation |
| Maintainers | redvanisation |

## Links

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

## Dependencies (2)

- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2
- [react-cookie](https://npm.io/package/react-cookie.md) ^4.0.3

## Recent versions

- 1.0.4 (latest) — 2020-04-17
- 1.0.3 — 2020-04-17
- 1.0.2 — 2020-04-17
- 1.0.1 — 2020-04-17
- 1.0.0 — 2020-04-17

## README

# react-cookies-users-provider

> Provides the logged in user after saving them in a cookie

[![NPM](https://img.shields.io/npm/v/react-cookies-users-provider.svg)](https://www.npmjs.com/package/react-cookies-users-provider) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm install --save react-cookies-users-provider
```

## Usage

Import the component and wrap it around the components that where you want the user context to be accessible:
```jsx
// index.js
import React from 'react'
import ReactDOM from 'react-dom'
import { UsersProvider } from 'react-cookies-users-provider'
import App from './App'

ReactDOM.render(
  <UsersProvider>
    <App />
  </UsersProvider>, 
  document.getElementById('root'))
```

Get the context and set a cookie, it will be accessible in the component and in your browser's cookies:

```jsx
// App.js
import React, { useContext } from "react";
import { UserContext } from "react-cookies-users-provider";

const App = () => {
  const userCtx = useContext(UserContext);


  return (
    <div onLoad={userCtx.setCookie("user", { name: "user-1", email: "user-1@example.com" })}>
      {userCtx ? (
        <>
          <h3>{userCtx.cookies.user.name}</h3>
          <h3>{userCtx.cookies.user.email}</h3>
        </>
      ) : null}
    </div>
  );
};
```

## License

MIT © [Redvanisation](https://github.com/Redvanisation)

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