Last active
October 31, 2017 13:12
-
-
Save Chalarangelo/a0b5e6f777356fda9814cbd86eb3abef to your computer and use it in GitHub Desktop.
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
// Import necessary packages... | |
class App extends Component { | |
// Constructor and methods... | |
// Mounting the component causes an action | |
componentDidMount(){ | |
fetch("https://jsonbin.io/b/59f721644ef213575c9f6531") | |
.then( response => response.json()) | |
.then( data => { | |
let posts = { | |
data: data | |
}; | |
this.updatePosts(posts); | |
}); | |
} | |
// render() -> Remember to change this.state to this.props | |
} | |
// mapStateToProps and connect as before |
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
// Import necessary packages... | |
const posts = (state = {data: []}, action) => { | |
let posts = {data: []}; | |
switch(action.type){ | |
case VIEW_ALL: | |
// TODO: Return all posts | |
return posts; | |
case SEARCH_POST: | |
// TODO: Return posts matched in search | |
return posts; | |
case UPDATE_POSTS: | |
// Copy data from the action to the global state | |
Object.assign(posts.data, action.posts.data); | |
return posts; | |
default: | |
return state; | |
} | |
} | |
export default posts; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment