# strictly-formed

> statically typed forms for typescript

Latest version **0.3.3** (published 2023-09-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install strictly-formed
pnpm add strictly-formed
yarn add strictly-formed
bun add strictly-formed
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.3.3 |
| Published | 2023-09-25 |
| First published | 2018-08-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 26.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | James Conkling |
| Maintainers | mmoorer90, james.lane.conkling, julietadams, mggower |
| Keywords | typescript, react, form |

## Links

- npm: https://www.npmjs.com/package/strictly-formed
- Repository: https://github.com/sayari-analytics/strictly-formed
- Homepage: https://github.com/sayari-analytics/strictly-formed#readme
- Issues: https://github.com/sayari-analytics/strictly-formed/issues
- npm.io page: https://npm.io/package/strictly-formed

## 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.3.3 (latest) — 2023-09-25
- 0.3.3-rc.1 — 2022-12-13
- 0.3.2 — 2022-09-12
- 0.3.1 — 2022-08-05
- 0.3.0 — 2022-05-12
- 0.3.0-rc.6 — 2022-04-27
- 0.3.0-rc.5 — 2022-04-25
- 0.3.0-rc.4 — 2022-04-22
- 0.3.0-rc.3 — 2022-04-15
- 0.3.0-rc.2 — 2022-04-14
- 0.3.0-rc.1 — 2022-04-13
- 0.3.0-rc.0 — 2022-04-13
- 0.2.4 — 2019-01-11
- 0.2.3 — 2018-10-24
- 0.2.2 — 2018-08-22
- … 4 more at https://npm.io/package/strictly-formed/versions

## README

# Strictly Formed

Component state bindings for redux and typescript

### Install

```bash
npm install strictly-formed
```

# API

### Redux Store

- **strictly-formed** state expects to be mapped under the reducer key `components`.

```typescript
  import { combineReducers, createStore } from 'redux'
  import { componentStateReducer, ComponentState, ComponentStateAction } from 'strictly-formed'

  export type Action = ComponentStateAction // ...
  export type State = {
    // ...
    components: ComponentState
  }

  export const store = createStore(
    combineReducers({
      // ...
      components: componentStateReducer,
    }),
    // ...
  )
```


### useComponentState
- an unopinionated state hook bound to redux.
- the interface is modeled after `React.useState`
- the `createId` utility will generate an ID that is bound to the component type. This will enable you to access the component state from redux without needing type assertions.

```typescript
export const useComponentState: <Component>(id: Id<Component>, initial: Component) => [
  Component,
  (value?: Component | ((state: Component) => Component)) => void,
  boolean
]
```

- example:
```typescript
import { useComponentState, createId } from 'strictly-formed'

type State = {
  name: string
  age?: number
}

const COMPONENT_ID = createId<State>('COMPONENT_ID')

const Component = (props) => {
  const [state, set, exists] = useComponentState(COMPONENT_ID, { name: '' })
  // ...
}

```

#### Action Creators

**setComponent**

```typescript
export const setComponent: <Component>(id: Id<Component>, value: Component) => {
    type: 'SET_COMPONENT';
    id: Id<Component>;
    value: Component;
};
```

**clearComponent**

```typescript
export const clearComponent: <Component>(id: Id<Component>) => {
    type: 'CLEAR_COMPONENT';
    id: Id<Component>;
};
```

#### Selectors

**getComponentState** requires an "initial" argument, this will be returned if the component's state has not yet been initialized in redux. The returned value will always be typeof Component

```typescript
export const getComponentState: <Component>(state: State, id: Id<Component>, initial: Component) => Component
```

**getComponent** will return undefined if the state has not been initialized in redux

```typescript
export const getComponent: <Component>(state: State, id: Id<Component>) => Component | undefined
```

**componentExists** will return boolean value determining whether the component's state exists within redux

```typescript
export const componentExists: <Component>(state: State, id: Id<Component>) => boolean
```


### License

[ISC](https://opensource.org/licenses/ISC)

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