0
私はreduxを持っていて、正しく反応していると私は信じています。子コンポーネントがアクションをオフにして、それを親コンポーネントのmapStatetoDispatch
メソッドに新しい状態にします。しかし、私はコンソールのログを通してこの状態が本当に新しいことを確認することができますが、レンダリングメソッドにヒットすることはありません(小道具は未定義に戻ってきます。新しい状態でコンポーネントのレンダリングメソッドが表示されないのはなぜですか?
私は何か基本的なものを見逃しているに違いない、私はすべてのコンポーネントのアップデートや次の状態のメソッドを試してみました。ここに私のコンポーネントである:
https://gist.github.com/geoffreysmith/ff909437a29ae8ab8db8038276b4f3b2
ありがとうございました!
編集:私はmapStateToProps
は、オブジェクト(props
)を返すべきであると考えてい
import { combineReducers } from 'redux';
import { routerReducer as routing } from 'react-router-redux'
import { ADD_NEW_REPORT } from '../actions/Dashboard';
function reports(state = {}, action) {
switch (action.type) {
case ADD_NEW_REPORT:
return Object.assign({}, state, { [action.index]: addReport(undefined, action) })
default:
return state
}
}
function addReport(state, action) {
switch (action.type) {
case ADD_NEW_REPORT:
return {
index: action.index,
siteAddress: action.siteAddress,
receivedAt: action.receivedAt,
status: action.status
}
default:
return state
}
}
const rootReducer = combineReducers({
reports,
routing
})
export default rootReducer
何あなたの減速が見えますか?更新しないコンポーネントの最も一般的な原因は、リデューサ内のデータの偶発的な変更です(http://redux.js.org/docs/FAQ.html#react-not-rerendering)。あなたは「小道具は未定義です」と言っているので、それはここでは問題ではないかもしれません。それでもあなたの状態の形を見るのに役立ちます。 – markerikson