Skip to content

Instantly share code, notes, and snippets.

View francisngo's full-sized avatar

Francis Ngo francisngo

View GitHub Profile
@francisngo
francisngo / reducers.js
Last active December 30, 2017 00:47
Collection for Redux todo example - This file defines the reducer function
import { types } from './actions';
const initialState = {
todos: ['Plan web app', 'Analyze use of app', 'Design and develop app', 'Test app', 'Implement and maintain app']
};
export const reducer = (state = initialState, action) => {
const { todos } = state;
const { type, payload } = action;
@francisngo
francisngo / App.js
Last active December 30, 2017 00:47
Collection for Redux todo example - This file is the "smart" container component. It is aware of the application's state and can fire actions to update state, using the actionCreators. The container subscribes to the store, updating its own state and the props of its children whenever the store's state changes.
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { actionCreators } from './actions';
import Input from './Input';
import List from './List';
class App extends Component {
constructor(props) {
super(props);
this.state = {};
@francisngo
francisngo / List.js
Created December 30, 2017 00:50
Collection for Redux todo example - This file is the presentational component for List
import React, { Component } from 'react';
export default class List extends Component {
renderItem(text, i) {
const { onClickItem } = this.props;
return (
<div onClick={() => onClickItem(i)}>{text}</div>
);
};
@francisngo
francisngo / Input.js
Created December 30, 2017 00:51
Collection for Redux todo example - This file is the presentational component for Input
import React, { Component } from 'react';
export default class Input extends Component {
constructor(props) {
super(props);
this.state = {
value: ''
};
this.handleChange = this.handleChange.bind(this);
this.handleKeyPress = this.handleKeyPress.bind(this);