Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
strictly-formed
Advanced tools
Component state bindings for redux and typescript
npm install strictly-formed
components
. 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,
}),
// ...
)
React.useState
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.export const useComponentState: <Component>(id: Id<Component>, initial: Component) => [
Component,
(value?: Component | ((state: Component) => Component)) => void,
boolean
]
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: '' })
// ...
}
setComponent
export const setComponent: <Component>(id: Id<Component>, value: Component) => {
type: 'SET_COMPONENT';
id: Id<Component>;
value: Component;
};
clearComponent
export const clearComponent: <Component>(id: Id<Component>) => {
type: 'CLEAR_COMPONENT';
id: Id<Component>;
};
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
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
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
export const componentExists: <Component>(state: State, id: Id<Component>) => boolean
FAQs
statically typed forms for typescript
The npm package strictly-formed receives a total of 4 weekly downloads. As such, strictly-formed popularity was classified as not popular.
We found that strictly-formed demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.