私の Redux ストアには、スレッドの配列と返信の配列があります。各返信には、スレッドに関連付けるためのスレッド ID があります。データベースからスレッドを取得すると、返信カウントは返されるプロパティの 1 つであり、そのカウントはスレッドと一緒に Web ページに表示されます。
ユーザーが新しい返信を追加すると、私の課題が表面化します。API は、新しい返信を返信コレクションに追加するのに十分な情報を返します。しかし、スレッド配列内にあるスレッドの応答カウント プロパティも増やしたいと考えています。どうすればいいですか?
これらは私の(簡略化された)レデューサーです:
const thread = (state = {}, action) => {
let nextState = state
if (action.type === C.POST_MESSAGE) {
nextState = action.payload
}
return nextState
}
const threads = (state = initialState.threads, action) => {
let nextState = state
if (action.type === C.POST_MESSAGE) {
nextState = [thread(null, action), ...state]
}
return nextState
}
const reply = (state = {}, action) => {
let nextState = state
if (action.type === C.POST_REPLY) {
nextState = action.payload
}
return nextState
}
const replies = (state = initialState.replies, action) => {
let nextState = state
if (action.type === C.POST_REPLY) {
nextState = [...state, action.payload]
}
return nextState
}