Skip to content

Instantly share code, notes, and snippets.

@Chalarangelo
Last active October 31, 2017 13:12
Show Gist options
  • Save Chalarangelo/a0b5e6f777356fda9814cbd86eb3abef to your computer and use it in GitHub Desktop.
Save Chalarangelo/a0b5e6f777356fda9814cbd86eb3abef to your computer and use it in GitHub Desktop.
// 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
// 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