I'm learing redux with react. I know that to rerender the tree you have to subscribe to some function and dispatch the action, I've done this
let render = store => {
ReactDOM.render(
<Provider store={store}><App /></Provider>,
document.getElementById('root')
)
}
render(store)
store.subscribe( () => {
render(store)
})
The dispatch works perfectly, I will not show the code because it does not matter in the way that the problem is about the time when I am truing to load data from the redux store using connect and there is 2 ways, of dispatching to the store, first:
state.articles.push({ title: action.article.title, id: action.article.id })
return state
second:
return Object.assign({}, state, {
articles: state.articles.concat({
id: action.article.id,
title: action.article.title
})
});
And the problem is that only second one works, saying works I mean it updates the LIST component and maps throw redux state
may be need to understand the problem, LIST component:
const mapStateToProps = state => {
return { articles: state.root.articles }
}
const ConnectedList = ({ articles }) => (
<ul className="list-group list-group-flush">
{articles.map(el => (
<li className="list-group-item" key={el.id}>
{el.title}
</li>
))}
</ul>
)
export default connect(mapStateToProps)(ConnectedList)