Skip to content

Instantly share code, notes, and snippets.

export const fetchAllStart = () => {
return {
type: constants.FETCH_ALL
};
};
export const fetchAllSuccess = (items) => {
return {
type: constants.FETCH_ALL_SUCCESS,
items
// import { createStore, applyMiddleware, compose } from 'redux';
// import rootReducer from '../rootReducer';
// import createLogger from "redux-logger";
// import thunkMiddleware from "redux-thunk";
const loggerMiddleware = createLogger();
const initialState = {
someProperty: []
};
/*
expected state:
{
accounts: {
items: []
isFetching: boolean
fetchingErrorMessage: string
}
}
// action types
// import types from 'actionTypes.js'
function accounts(state = [], action) {
switch(action.type) {
case types.ADD_ACCOUNT:
return [
...state,
{
id: getNewId(), //fake method that returns new ID
// action types
const ADD_ACCOUNT = "ADD_ACCOUNT";
// action
const addAccountAction = {
type: ADD_ACCOUNT,
title: "Account title",
createdBy: "admin"
};
class MyForm extends Component {
constructor() {
super();
this.state = {
value: "Hello!"
}
//bindings here
}
class MyComponent extends Component {
constructor(props) {
super(props);
this.state = { value: { foo: 'bar' } };
}
onClick() {
var value = this.state.value;
value.foo += 'bar'; // value is reference to the current state, so current state and next state will be the same in next SCU call...
class MyComponent extends Component {
render() {
return <main>Awesome component</main>;
}
}
MyComponent.propTypes = {
count: PropTypes.number.isRequired,
items: PropTypes.arrayOf(
PropTypes.shape({
const MY_CONST = 44;
function doMagic(regularStuff) {
return "magical stuff";
}
export class MyComponent extends Component {
render() {
return (
<main>
<p>Some text</p>
// MyComponent.jsx
export class MyComponent extends Component {
constructor(props) {
super(props);
this.state = {counter: 0};
this.onButtonClick = this.onButtonClick.bind(this);
}