part 2 - redux
Binar::apps
Redux is a predictable state container for JavaScript apps.
payloads of information that send data from your application to your store.
{
type: 'ADD_TODO',
todo: {...}
}
Action creators are functions that create actions.
function addTodo(todo) {
return {
type: 'ADD_TODO',
todo: todo
}
}
// reducer
const reducer = (state = defaultState, action ) => {
switch(action.type) {
case 'ADD_TODO':
return [...state, action.todo];
default:
return state;
}
}
import {connect} from 'react-redux';
import {toggle} from 'actions/toeats';
import ToeatList from 'components/toeat-list';
const mapStateToProps = (state) => {
return {
toeats: state.toeats
};
};
const mapDispatchToProps = (dispatch) => {
return {
onCheckItem: (name) => {
dispatch(toggle(name));
}
};
};
export default connect(mapStateToProps, mapDispatchToProps)(ToeatList);