Connect input components to redux by passing an action and a selector.
npm install --save redux-input
import React from 'react'
import { ReduxInput } from 'redux-input'
import { DatePicker } from 'antd'
import selectors from './selectors'
import actions from './actions'
const BasicExample = () => {
return (
<ReduxInput
Component={DatePicker}
selector={selectors.basicExampleInput}
action={actions.basicExampleAction}
/>
)
}
// selectors.js
const basicExampleInput = (state) => state.basic.example.input
// actions.js
const basicExampleAction = (payload) => ({
type: 'BASIC_EXAMPLE/CHANGE',
payload,
})
// reducer.js
import { createReducer } from '@reduxjs/toolkit'
combineReducers({
input: createReducer(null, {
'BASIC_EXAMPLE/CHANGE': (_, { payload }) => payload
})
})
Further examples are documented here
MIT © danielrob