# react-use-context

> Use-Context

Latest version **1.0.2** (published 2022-07-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-use-context
pnpm add react-use-context
yarn add react-use-context
bun add react-use-context
```

## 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.2 |
| Published | 2022-07-03 |
| First published | 2022-07-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | chamal0f |

## Links

- npm: https://www.npmjs.com/package/react-use-context
- Repository: https://github.com/Chamal0f/react-use-context
- Homepage: https://github.com/Chamal0f/react-use-context#readme
- Issues: https://github.com/Chamal0f/react-use-context/issues
- npm.io page: https://npm.io/package/react-use-context

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^18.2.0
- [react-dom](https://npm.io/package/react-dom.md) ^18.2.0

## Recent versions

- 1.0.2 (latest) — 2022-07-03
- 1.0.1 — 2022-07-03
- 1.0.0 — 2022-07-03

## README

<h1>Use-Context</h1>

Alpha version of a wrapper around react context to simplify it's creation.
use only react and is typescript compatible.
export 3 modules, a provider, a state hook with selector (not memoized to prevent rerender) and an action hook.


``` 
import {createContext} from "react-use-context";


type TState = {
  variable1: string,
  variable2: number
}

type TActions = {
  modifyVariable1: (state: TState, payload: string) => TState
  modifyVariable2: (state: TState, payload: number) => TState
}

export const { useStore, Provider, useActions } = createContext<TState, TActions>({
  initialState: {
    variable1: "variable1",
    variable2: 3
  },
  actions: {
    modifyVariable1 : (state, payload  ) => {
      return { ...state,variable1: payload }
    },
    modifyVariable2 : (state, payload  ) => {
      return { ...state,variable2: payload }
    },
  }
});


function App() {

  return (
      <Provider>
        <div className="App">
          <SubComponent />
          <SubComponent2 />
        </div>
      </Provider>


  )
}

const SubComponent = () => {
  const {modifyVariable1} = useActions()
  return <button onClick={() => modifyVariable1("newVariable1")}  > update </button>
}

const SubComponent2 = () => {
  const variable1 = useStore(state=> state.variable1)
  return <span>{variable1}</span>;
}



export default App

```

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