Redux操作changePictogramsKeyword未被解僱。Redux操作未被解僱
這是我定義我的動作和減速機(終極版/模塊/ keyword.js)文件:
export const CHANGE_PICTOGRAMS_KEYWORD = 'CHANGE_PICTOGRAMS_KEYWORD'
export function changePictogramsKeyword (keyword) {
return {
type: CHANGE_PICTOGRAMS_KEYWORD,
keyword
}
}
// Updates error message to notify about the failed fetches.
export default function pictogramsKeyword (state = '', action) {
switch (action.type) {
case CHANGE_PICTOGRAMS_KEYWORD:
return action.keyword
default:
return state
}
}
我的根減速機:
import { combineReducers } from 'redux'
import { routerReducer as router } from 'react-router-redux'
import locale from './modules/locale'
import errorMessage from './modules/error'
import pictogramsKeyword from './modules/keyword'
export default combineReducers({
locale,
router,
pictogramsKeyword,
errorMessage
})
與我可以檢查devTools
所以我的初始化狀態是我從rootReducer預期:
locale:"en"
router:{} 1 key
pictogramsKeyword:""
errorMessage:null
這是視圖的代碼,我連接到Redux商店。組件SearchBox負責發起動作changePictogramsKeyword:
import React, {Component, PropTypes} from 'react'
import SearchBox from 'components/SearchBox.js'
import { connect } from 'react-redux'
import { changePictogramsKeyword } from 'redux/modules/keyword'
class SearchPictogramsView extends Component {
handleDismissClick (e) {
this.props.resetErrorMessage()
e.preventDefault()
}
render() {
const { children, inputValue } = this.props
return (
<div>
<SearchBox value={inputValue} onChange={changePictogramsKeyword} />
{children}
</div>
)
}
}
SearchPictogramsView.propTypes = {
inputValue: PropTypes.string.isRequired,
children: PropTypes.node
}
function mapStateToProps (state, ownProps) {
return {
errorMessage: state.errorMessage,
inputValue: state.pictogramsKeyword
}
}
export default connect(mapStateToProps, {
resetErrorMessage, changePictogramsKeyword
})(SearchPictogramsView)
這是SearchBox組件的代碼。 AutoComplete是一個材料UI組件。 onUpdateInput方法得到射擊每次我按一個鍵,但是changePictogramsKeyword不被解僱(我什麼也看不到,通過開發者工具)
import React, {Component, PropTypes} from 'react'
import AutoComplete from 'material-ui/lib/auto-complete'
import RaisedButton from 'material-ui/lib/raised-button'
class SearchBox extends Component {
constructor (props) {
super(props)
this.handleUpdateInput = this.handleUpdateInput.bind(this)
}
handleUpdateInput = (t) => {
console.log(t)
this.props.onChange(t)
}
render() {
return (
<div>
<AutoComplete onUpdateInput={this.handleUpdateInput} searchText={this.props.value} />
</div>
)
}
}
SearchBox.propTypes = {
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired
}
export default SearchBox
您的代碼無法解決問題。我認爲這也是我寫的。我在連接方法中的第二個參數是一個對象...,並從文檔:如果一個對象被傳遞,其中的每個函數將被認爲是一個Redux行動的創造者。一個具有相同函數名稱的對象,但每個動作創建者都被包裝成一個調度調用,以便它們可以被直接調用,將被合併到組件的道具中 – user2670996
URL:https://github.com/reactjs/react-redux/斑點/主/文檔/ API。md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options – user2670996
TIL,我的不好。我不知道這是否奏效,很高興你找到了解決方案! – mxstbr