This file contains hidden or 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
| export const fetchAllStart = () => { | |
| return { | |
| type: constants.FETCH_ALL | |
| }; | |
| }; | |
| export const fetchAllSuccess = (items) => { | |
| return { | |
| type: constants.FETCH_ALL_SUCCESS, | |
| items |
This file contains hidden or 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 { 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: [] | |
| }; |
This file contains hidden or 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
| /* | |
| expected state: | |
| { | |
| accounts: { | |
| items: [] | |
| isFetching: boolean | |
| fetchingErrorMessage: string | |
| } | |
| } |
This file contains hidden or 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
| // 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 |
This file contains hidden or 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
| // action types | |
| const ADD_ACCOUNT = "ADD_ACCOUNT"; | |
| // action | |
| const addAccountAction = { | |
| type: ADD_ACCOUNT, | |
| title: "Account title", | |
| createdBy: "admin" | |
| }; |
This file contains hidden or 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
| class MyForm extends Component { | |
| constructor() { | |
| super(); | |
| this.state = { | |
| value: "Hello!" | |
| } | |
| //bindings here | |
| } | |
This file contains hidden or 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
| 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... |
This file contains hidden or 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
| class MyComponent extends Component { | |
| render() { | |
| return <main>Awesome component</main>; | |
| } | |
| } | |
| MyComponent.propTypes = { | |
| count: PropTypes.number.isRequired, | |
| items: PropTypes.arrayOf( | |
| PropTypes.shape({ |
This file contains hidden or 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
| const MY_CONST = 44; | |
| function doMagic(regularStuff) { | |
| return "magical stuff"; | |
| } | |
| export class MyComponent extends Component { | |
| render() { | |
| return ( | |
| <main> | |
| <p>Some text</p> |
This file contains hidden or 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
| // MyComponent.jsx | |
| export class MyComponent extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = {counter: 0}; | |
| this.onButtonClick = this.onButtonClick.bind(this); | |
| } | |