# rema

> Transfers state from one component to another and manipulates their values.

Latest version **1.0.0-alpha.2.1** (published 2025-05-04) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.2.1 |
| Published | 2025-05-04 |
| First published | 2025-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 18.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Erick |
| Maintainers | ertrii |
| Keywords | react, render, keyNames, reducers, state |

## Links

- npm: https://www.npmjs.com/package/rema
- Repository: https://github.com/ertrii/rema
- Homepage: https://github.com/ertrii/rema.git
- Issues: https://github.com/ertrii/rema.git/issues
- npm.io page: https://npm.io/package/rema

## 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.0-alpha.2.1 (latest) — 2025-05-04
- 1.0.0-alpha.2 — 2025-05-02
- 1.0.0-alpha.1.4 — 2025-02-06
- 1.0.0-alpha.1.3 — 2025-02-06
- 1.0.0-alpha.1.2 — 2025-02-06
- 1.0.0-alpha.1.1 — 2025-02-06
- 1.0.0-alpha.1 — 2025-02-06

## README

# RemaJS

Transfers state from one component to another and manipulates their values.

## Installation

```
npm install rema
```

Import provider

```tsx
import { RemaProvider } from "rema";

createRoot(document.getElementById("root")!).render(
  <RemaProvider>
    <App />
  </RemaProvider>
);
```

## Initialice states

```tsx
// MainComponent.jsx
import { useInit } from "rema";
function MainComponent() {
  const [state, setState] = useInit("MAIN_COMPONENT", { counter: 0 });
  return (
    <div>
      <p>{state.counter}</p>
      <button onClick={() => setState({ counter: state.counter + 1 })}>
        Counter
      </button>
    </div>
  );
}

// OtherComponent.jsx
import { useListen } from "rema";
function OtherComponet() {
  const { counter } = useListen("MAIN_COMPONENT");
  const emit = useEmit("MAIN_COMPONENT");
  return (
    <div>
      <p>{counter}</p>
      <button onClick={() => emit({ counter: state.counter + 1 })}>
        Counter
      </button>
    </div>
  );
}
```

## Using Reducer

```tsx
// MainComponent.tsx
import { useInitReducer } from "rema";
export interface MainComponentState {
  color: string;
}
export type MainComponentAction =
  | { type: "CHANGE_COLOR"; payload: string }
  | { type: "RESET_COLOR" };
function reducer(state: MainComponentState, action: MainComponentAction) {
  switch (action.type) {
    case "CHANGE_COLOR":
      return { ...state, color: action.payload };
    case "RESET_COLOR":
      return { ...state, color: "black" };
    default:
      return state;
  }
}
function MainComponent() {
  const [state, dispatch] = useInitReducer("MAIN_COMPONENT", reducer, {
    color: "black",
  });
  return (
    <div>
      <p style={{ color: state.color }}>{state.color}</p>
      <button
        onClick={() => dispatch({ type: "CHANGE_COLOR", payload: "red" })}
      >
        Red Color
      </button>
    </div>
  );
}

// OtherComponent.tsx
import { useListen } from "rema";
function OtherComponet() {
  const { color } = useListen("MAIN_COMPONENT");
  const dispatch = useDispatch("MAIN_COMPONENT");
  return (
    <div>
      <p style={{ color }}>{color}</p>
      <button
        onClick={() => dispatch({ type: "CHANGE_COLOR", payload: "blue" })}
      >
        Blue Color
      </button>
    </div>
  );
}
```

## Unsubscribe states

Resets the state when the component is unmounted

```tsx
function ParentComponent{
  useUnsubscribe("MAIN_COMPONENT")
  return <>{/*...*/}</>
}
```

## useReserve

Replaces the initial state that the parent component initializes.

```tsx
const emit = useReserve("MAIN_COMPONENT");

<button onClick={() => emit({ count: 7 })}>Prev states</button>;
```

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