I'm trying to understand how redux works using the example code from the blog tutorial, but I can't figure out how the connect
function works in this example. Please explain in detail.
Function connect, I don't understand (items) => items, PostListActions
export default connect((items) => items, PostListActions)(PostListContainer);
import React from 'react';
import {connect} from 'react-redux';
import {PostList} from '../../../components/PostList';
import PostListActions from "./../actions";
export class PostListContainer extends React.Component {
componentWillMount() {
const {fetchItems} = this.props;
fetchItems();
}
render() {
const {fetchRemoveItem} = this.props;
return <PostList posts={this.props.posts.items} onRemove = {fetchRemoveItem}/>;
}
}
export default connect((items) => items, PostListActions)(PostListContainer);
import {postApi} from './../../utils/api';
const PostListActions = {
setItems: (items) => ({
type: 'POSTS:SET_ITEMS',
payload: items
}),
removeItems: (id) => ({
type: 'POSTS:REMOVE_ITEM',
payload: id
}),
fetchItems: () => dispatch => {
postApi.getNotes().then(({data}) => {
dispatch(PostListActions.setItems(data));
});
},
fetchRemoveItem: (id) => dispatch => {
dispatch(PostListActions.removeItems(id));
postApi.deleteNote(id);
}
};
export default PostListActions;