Redux - I don't understand "Task-Based Updates" example -
in link: task-based updates don't understand below code:
import posts "./postsreducer"; // missing code?? import comments "./commentsreducer"; // missing code?? and why should that?
const combinedreducer = combinereducers({ posts, comments }); const rootreducer = reducereducers( combinedreducer, featurereducers ); only featurereducers okie? not need combindedreducer? anh postsreducer code, commentsreducer code?
thanks helps!
unfortunately example little confusing (one of few places in solid redux docs). if go here , check out 'third approach', you'll see concept explained little better.
essentially, postreducer , commentreducer there handle actions modify posts or comments--that is, things not require changes multiple tables (e.g posts , comments). featurereducer task-based reducer handles actions require updates multiple tables.
a simplified example:
const postreducer = (state = {}, action) => { return state } const commentreducer = (state = {}, action) => { return state } const combined = combinereducers({ posts: postreducer, comments: commentreducer }) const createcomment = (state, action) => { switch(action.type) { case 'create_comment': // update multiple tables (linked example ok job ok demonstrating this) return updatedstate default: return state; } } const rootreducer = reducereducers( combined, createcomment ) in example, first 2 reducers create state shape. third, depends on first 2 set state it, updates multiple tables across redux store.
your state shape this:
{ posts: {}, comments: {} } if you're confused reducereducers, try think of combinereducers, doesn't affect state shape.
Comments
Post a Comment