Я пытаюсь передать переменную в действие Redux , но действие получает undefined , что я делаю не так?
index. js - где я вызываю действие
import React from 'react'
import { connect } from 'react-redux'
import * as documentActions from '../../services/redux/actions/document'
function Document(props) {
return (
<ul className="list-group group">
<li className="list-group-item group-item"
name = 'group'
onClick={() => props.toggleDoc(1)}>
{props.data.name}
</li>
</ul>
)
}
const mapStateToProps = state => {
return {
selectedId: state.selectedId
}
}
const mapDispatchToProps = dispatch => {
return {
toggleDoc: () => dispatch(documentActions.toggleDoc())
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(Document)
документ. js - где действие
import * as types from '../types'
export function toggleDoc(id) {
return {
type: types.TOGGLE_DOC,
payload: id
}
}
reducer
import * as types from '../types'
const initialState = {
selectedId: null
}
export default function toggleDoc(state = initialState, action) {
console.log('action')
console.log(action.payload)
switch (action.type) {
case types.TOGGLE_DOC:
return {
...initialState,
selectedId: action.payload
}
default:
return state
}
}
Что печатает:
что печатать:
action
1