This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return ( | |
<ul> | |
{items.map(item => ( | |
<li key={item.ID}> | |
{item.title} | |
{item.content} | |
</li> | |
))} | |
</ul> | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Awesome sandbox: https://codesandbox.io/s/13on9ykl1l | |
// Redux: | |
const ADD = 'ADD'; | |
const addMessage = (message) => { | |
return { | |
type: ADD, | |
message: message | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const addMessage = (message) => { | |
return { | |
type: 'ADD', | |
message: message | |
} | |
}; | |
// change code below this line | |
const mapDispatchToProps = dispatch => { | |
return { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Redux Code: | |
const ADD = 'ADD'; | |
const addMessage = (message) => { | |
return { | |
type: ADD, | |
message | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define ADD, addMessage(), messageReducer(), and store here: | |
const ADD = 'ADD'; | |
const messageReducer = (state = [], action) => { | |
switch(action.type) { | |
case ADD: | |
return [ | |
...state, | |
action.message | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DisplayMessages extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
input: '', | |
messages: [] | |
} | |
this.handleChange = this.handleChange.bind(this); | |
this.handleSubmit = this.handleSubmit.bind(this); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const defaultState = { | |
user: 'CamperBot', | |
status: 'offline', | |
friends: '732,982', | |
community: 'freeCodeCamp' | |
}; | |
const immutableReducer = (state = defaultState, action) => { | |
switch(action.type) { | |
case 'ONLINE': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const immutableReducer = (state = [0,1,2,3,4,5], action) => { | |
switch(action.type) { | |
case 'REMOVE_ITEM': | |
// don't mutate state here or the tests will fail | |
return [ | |
...state.slice(0, action.index), | |
...state.slice(action.index + 1, state.length) | |
] | |
default: | |
return state; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const INCREMENT = 'INCREMENT'; // define a constant for increment action types | |
const DECREMENT = 'DECREMENT'; // define a constant for decrement action types | |
const counterReducer = (state = 0, action) => { | |
switch(action.type) { | |
case INCREMENT: | |
return state + 1 | |
case DECREMENT: | |
return state - 1 | |
default: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const REQUESTING_DATA = 'REQUESTING_DATA' | |
const RECEIVED_DATA = 'RECEIVED_DATA' | |
const requestingData = () => { return {type: REQUESTING_DATA} } | |
const receivedData = (data) => { return {type: RECEIVED_DATA, users: data.users} } | |
const handleAsync = () => { | |
return function(dispatch) { | |
// dispatch request action here | |
dispatch(requestingData()); |
NewerOlder