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 { CHANGE_TEAM } from 'modules/Team/Team'; | |
const getCurrentTeamId = () => window.localStorage.getItem('current-team'); | |
const readTeamData = teamId => { | |
const newStateData = window.localStorage.getItem(`team-data-${teamId}`); | |
if (newStateData) { | |
return JSON.parse(newStateData); | |
} |
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 Child extends Component { | |
state = this.props.cachedState | |
? this.props.cachedState | |
: { | |
value: 0, | |
}; | |
componentWillUnmount() { | |
if (this.props.saveState) { | |
this.props.saveState(this.state); |
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 api from './api'; | |
export const ADD_PHOTOS = 'Photos/ADD_PHOTOS'; | |
export function addPhotos(photos) { | |
return { | |
type: ADD_PHOTOS, | |
payload: photos, | |
}; | |
} |
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 { ADD_PHOTOS } from './actions'; | |
function getInitialState() { | |
return { | |
photos: [], | |
}; | |
} | |
export default function reducer(state = getInitialState(), action) { | |
switch (action.type) { |
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 { connect } from 'react-redux'; | |
import PhotoList from 'components/PhotoList'; | |
import { fetchPhotos } from './modules/Photos/actions'; | |
const mapStateToProps = state => ({ | |
photos: state.photos.photos, | |
}); | |
const mapDispatchToProps = { |
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 { Component, createContext } from 'react'; | |
import PropTypes from 'prop-types'; | |
import api from './api'; | |
const { Consumer, Provider } = createContext({ | |
photos: [], | |
}); | |
export { Consumer }; |
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 { PhotosConsumer } from './contexts'; | |
import PhotoList from 'components/PhotoList'; | |
export default function ContextPhotoListContainer() { | |
return ( | |
<PhotosConsumer> | |
{({ photos, fetchPhotos }) => <PhotoList photos={photos} fetchPhotos={fetchPhotos} />} | |
</PhotosConsumer> | |
); | |
} |
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 { combineReducers, createStore, applyMiddleware } from 'redux'; | |
import thunk from 'redux-thunk'; | |
import photos from './modules/Photos/reducer'; | |
const rootReducer = combineReducers({ photos }); | |
export default createStore(rootReducer, applyMiddleware(thunk)); |
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 'regenerator-runtime/runtime'; | |
import { render } from 'react-dom'; | |
import { Provider } from 'react-redux'; | |
import Container from 'components/Container'; | |
import ReduxPhotoListContainer from './ReduxPhotoListContainer'; | |
import store from './store'; | |
render( |
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 'regenerator-runtime/runtime'; | |
import { PhotosProvider } from './contexts'; | |
import Container from 'components/Container'; | |
import ContextPhotoListContainer from './ContextPhotoListContainer'; | |
import { render } from 'react-dom'; | |
render( | |
<PhotosProvider> |
OlderNewer