How to handle tree-shaped entities in Redux reducers?

后端 未结 2 979
我寻月下人不归
我寻月下人不归 2021-01-30 07:35

I\'m a bit stuck thinking on how to implement a reducer where its entities can have children of the same type.

Let\'s take reddit comments as an example: each comment ca

2条回答
  •  爱一瞬间的悲伤
    2021-01-30 08:08

    Your store (reducer) structure could differ from your desired view model (one you pass as props to components). You could just keep all comments in array and map them to a tree by links in mapStateToProps on high-level 'smart' component. You'll get simple state management in reducer and a handy view model for components to work with.

提交回复
热议问题