Redux Action Creator

What is the Actions

function addTodo(text) {
return {
type: ADD_TODO,
text
}
}
function addTodoWithDispatch(text) {const action = {type: ADD_TODO,text}dispatch(action)}
dispatch(addTodo(text))
dispatch(completeTodo(index))
const boundAddTodo = text => dispatch(addTodo(text))
const boundCompleteTodo = index => dispatch(completeTodo(index))
index.js
const store = createStore(playerReducer,composeEnchancers(applyMiddleware(thunk)))
PlayerReducer.jsexport default function playerReducer(state = {players: []}, action ) {
switch (action.type){
case 'FETCH_PLAYERS':
return {players: action.payload}
case 'ADD_PLAYER':
#We need another case to add player
return{...state, players: [...state.players, action.payload]}case 'ADD_CONTRACT':
return {...state, newContract:action.payload}case'DELETE_CONTRACT':
return {...state, newContract:action.payload.contract}
default:
return state
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Soner Mezgitci

Soner Mezgitci

31 Followers

Software Engineer | Ruby on Rails | JavaScript | HTML5 | CSS | PostgreSQL | React | Redux