Skip to content

Instantly share code, notes, and snippets.

import React, { Component } from 'react';
// Must use connect() here because we have our App.js wrapped in a Provider.
// Once there's a change in the state, the Provider will re-render this component
// because it is a child of App.js
import { connect } from 'react-redux';
//Below we are exporting the Tasks class so that we can call it in our
//connect(), method on the bottom.
export class Tasks extends Component {
import React, { Component } from "react";
export default class UserInput extends Component {
constructor(props) {
super(props);
this.state = {
export default function manageTasks(state = {
tasks: [],
}, action){
switch (action.type) {
case 'ADD_TASK':
return Object.assign({}, state, {
tasks: state.tasks.concat(action.task)
});
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
// Require the Provider library from react-redux below.
import { Provider } from 'react-redux';
// createStore is replacing the manual createStore that we've created in the
// previous lab.
import { createStore } from 'redux';
import React, { Component } from 'react';
class Band extends Component {
// When we are handing the click, we would ideally want to change our current
// state to remove this item. We need to call our dispatch function and include a DELETE
// type so we can impliment logic later in our manageBand.js.
handleClick(e){
e.preventDefault();
import React, { Component } from 'react';
class BandInput extends Component{
constructor(){
super();
this.state={
text: ""
}
import React, { Component } from 'react';
import Band from './Band';
class Bands extends Component {
render() {
const bands = this.props.store.getState().bands.map((band, index) => {
return <Band key={index} band={band} store={this.props.store} />
})
//See how we are passing in this.props.store
// manageBand is our state manager for Bands. Basically,
// instead of making changes in component states,
// we're going to be taking care of those state changes here when it
// comes to Bands.
//counter is just for the unique ID for our Delete case.
let counter = 0
export default function manageBand (state = {
bands: []
import React, { Component } from 'react';
import BandInput from './components/BandInput';
import Bands from './components/Bands';
class App extends Component{
// We have to continue passing in the function store into children
// components.
render(){
return(
import { renderer } from './index.js';
export default function createStore(reducer) {
// We're defining a new variable called state where we
// are going to set to be equal to the state in our reducer
let state;
function dispatch(action) {