@umpire/redux
@umpire/redux is the Redux integration for Umpire. Redux’s subscribe callback doesn’t carry previous state, so this adapter tracks it on your behalf. Everything else — select(), conditions, the UmpireStore surface — works the same as @umpire/zustand.
Install
Section titled “Install”yarn add @umpire/core @umpire/redux reduxfromReduxStore()
Section titled “fromReduxStore()”function fromReduxStore< S, F extends Record<string, FieldDef>, C extends Record<string, unknown> = Record<string, unknown>,>( ump: Umpire<F, C>, store: { getState(): S subscribe(listener: () => void): () => void }, options: FromStoreOptions<S, F, C>,): UmpireStore<F>Example
Section titled “Example”import { legacy_createStore } from 'redux'import { enabledWhen, umpire } from '@umpire/core'import { fromReduxStore } from '@umpire/redux'
const ump = umpire({ fields: { password: {}, confirmPassword: { default: '' }, }, rules: [ enabledWhen('confirmPassword', (values) => { return (values.password as string)?.length > 0 }), ],})
const store = legacy_createStore((state = { password: '', confirmPassword: '' }, action) => { if (action.type === 'patch') { return { ...state, ...action.payload } }
return state})
const umpStore = fromReduxStore(ump, store, { select: (state) => ({ password: state.password, confirmPassword: state.confirmPassword, }),})select()still solves split state. Pull from as many reducer slices as you need.- The returned
UmpireStoresurface is the same as@umpire/store. - If your store already passes previous state to subscribers, use
@umpire/zustandor@umpire/storedirectly instead.