# redext

> A simple global store based on React Context and Hooks

Latest version **0.1.1-dev-2** (published 2025-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install redext
pnpm add redext
yarn add redext
bun add redext
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

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

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1-dev-2 |
| Published | 2025-03-27 |
| First published | 2021-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 144.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | dotcody |
| Keywords | react, react-context, react-hooks |

## Links

- npm: https://www.npmjs.com/package/redext
- Repository: https://github.com/redextjs/redext
- Issues: https://github.com/redextjs/redext/issues
- npm.io page: https://npm.io/package/redext

## 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

- 0.1.1-dev-2 (latest) — 2025-03-27
- 0.1.1-dev-1 — 2025-03-27
- 0.1.1 — 2025-03-24
- 0.1.0 — 2024-08-08
- 0.0.17-dev-2 — 2024-08-08
- 0.0.17-dev-1 — 2024-08-08
- 0.0.17 — 2024-07-24
- 0.0.16-7 — 2024-07-18
- 0.0.16-6 — 2024-07-18
- 0.0.16-5 — 2024-07-18
- 0.0.16-4 — 2024-07-18
- 0.0.16-3 — 2024-07-18
- 0.0.16-2 — 2024-07-18
- 0.0.16-1 — 2024-07-18
- 0.0.1-6.1 — 2024-07-18
- … 34 more at https://npm.io/package/redext/versions

## README

# redext

A simple global store based on React Context and Hooks

##  Installation

```bash
npm install redext
or
yarn add redext
```

## Use It

```js
// store/models/common.ts
import React from 'react';

export default {
  state: {
    theme: 'white',
    showModal: false
  },
  effects: (dispatch) => {
    return {
      onOpenModal(modalState) {
        this.updateState({
          showModal: true,
          modalState
        });

        // or
        dispatch({
          type: 'common/updateState',
          payload: {
            showModal: true,
            modalState
          }
        });

        // or
        dispatch.common.updateState({
          showModal: true,
          modalState
        })
      }
    }
  },
  reducers: {
    updateState: (state, payload) => {
      if (typeof payload === 'function') {
        payload = payload(state);
      }
        
      return {
        ...state,
        ...payload
      };
    },
    changeTheme: (state) => {
      return {
        ...state,
        theme: state.theme === 'white' ? 'dark' : 'white'
      };
    }
  }
}
```

```js
// store/models/index.ts
import common from './common';
import auth from './auth';

export default {
  common,
  auth
}
```

```js
// store/index.ts
import { Provider, connect, init, models } from 'redext';

import models from './models';

export { Provider, connect, init, models }
```

```js
// client/index.ts
import { Provider, init, models } from './store';

const store = init({
  models
});

const App = ({ children, initialValue = {} }) => {
  return (
    <Provider store={store} initialValue={initialValue}>
       {children}
    </Provider>
  )
}

export default App
```

```js
// client/pages/home.ts
import { useDispatch, useSelector, useDispatcher } from 'redext';

const Home = (props) => {
  const dispatch = useDispatch();
  const theme = useSelector(({ common: { theme } }) => theme);
  const { onOpenModal } = useDispatcher(({ common: { onOpenModal } }) => ({ onOpenModal }));

  return (
    <div>
      {theme}
    </div>
  )
}

export default Home
```

```js
// client/pages/explore.ts
import { connect, memoize, useDeepEffect } from 'redext';

const Explore = ({ dispatch, theme, onOpenModal }) => {
  useDeepEffect(() => {
  }, [array, object]);
  
  return (
    <div>
      {theme}
    </div>
  )
}

const mapState = ({ common: { theme } }) => ({
  theme
});

const mapDispatch = ({ common: { onOpenModal } }) => ({
  onOpenModal
});

// options
const memoPropsAreEqual = (prevProps, nextProps) => {
  if (nextProps.visible !== prevProps.visible) {
    return false
  }

  return true
};

export default connect(mapState, mapDispatch)(memoize(Explore, memoPropsAreEqual))
```

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