Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rematch/typed-state

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rematch/typed-state

Rematch plugin for typing the state

  • 2.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
55
decreased by-40.22%
Maintainers
3
Weekly downloads
 
Created
Source

Typed-state

Rematch plugin for type-checking state at runtime. Uses prop-types for describing expected type shape.

Install

npm install @rematch/typed-state

If your project doesn't have prop-types package yet, you need to add it as well:

npm install prop-types

Setup

Use typings property to describe the shape of model's state, and add typed-state plugin when initializing a store:

import T from 'prop-types'
import { init } from '@rematch/core'
import typedStatePlugin from '@rematch/typed-state'

const user = {
	state: {
		name: 'Jon',
		age: 25,
		isDeveloper: true,
		address: {
			country: 'US',
			city: 'New York',
		},
	},
	typings: {
		name: T.string.isRequired,
		age: T.number.isRequired,
		isDeveloper: T.bool,
		address: T.shape({
			country: T.string.isRequired,
			city: T.string,
		}),
	},
	reducers: {
		updateName: (state, name) => ({
			name,
		}),
	},
}

const store = init({
	models: { user },
	plugins: [typedStatePlugin()],
})

With that in place, if you try to update the state with invalid value type, you'll get a warning in developer tools:

store.dispatch.user.updateName(undefined)

// > console.warn
// > [rematch] Invalid property `name` of type `undefined` supplied to `user`, expected `string`.

Please refer to prop-types documentation for a full list of available validations.

Keywords

FAQs

Package last updated on 09 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc