Skip to content

@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.

Terminal window
yarn add @umpire/core @umpire/redux redux
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>
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 UmpireStore surface is the same as @umpire/store.
  • If your store already passes previous state to subscribers, use @umpire/zustand or @umpire/store directly instead.