Skip to content

Instantly share code, notes, and snippets.

@graphan
graphan / pageComponent.jsx
Created March 12, 2017 11:20
withLoadingComponent
export const Page = ({ posts, scrollToTop }) => (
<div>
{posts && posts.map(post => (
<div key={post.title} dangerouslySetInnerHTML={{ __html: post.content }} />
))}
<a className="toTop" onClick={scrollToTop} />
</div>
);
........
@graphan
graphan / loadingComponent.js
Created February 19, 2017 18:55
Use of Recompose's branch for Loading Component
import { branch, renderComponent } from 'recompose';
const Loading = () => (
<div>Loading....</div>
);
export const withLoadingComponent = branch(
props => props.loading,
renderComponent(Loading),
);
@graphan
graphan / loadingApollo.js
Created February 19, 2017 18:52
Loading in Apollo
export const Component = ({ data: { loading, ... } }) => {
if (loading) {
...
return(<LoadingComponent>);
}
...
};
@graphan
graphan / oldOnClickHandler.js
Created February 19, 2017 18:45
Old way of handlers in React Components
export const Component = () => {
const onClickHandler = () => {
...
};
return (
<div onClick={onClickHandler}></div>
);
};
@graphan
graphan / withRecompose.js
Last active February 19, 2017 18:01
Creating Apollo and Redux Containers with Recompose
import { compose, withHandlers } from 'recompose';
// Component Code here
export default compose(
connect(mapStateToProps),
graphql(PAGE_QUERY, getOptions(['posts'])),
withLoadingComponent,
withHandlers(handlers)
)(Page);
@graphan
graphan / withoutRecompose.js
Last active June 16, 2017 08:52
Creating Apollo and Redux Containers without Recompose
export const LANG_QUERY = gql`
...
`;
const mapStateToProps = state => ({
language: state.language,
});
const mapDispatchToProps = dispatch => ({
changeLang: (lang) => {
dispatch(setLanguage(lang));