Skip to content

Instantly share code, notes, and snippets.

@trevorblades
trevorblades / ProductsList.js
Created July 19, 2019 18:18
Apollo render props vs. hooks (basic example)
function ProductsList() {
const {loading, error, data} = useQuery(LIST_PRODUCTS);
if (loading) return 'Loading...';
if (error) return error.message;
return (
<ul>
{data.products.map(product => (
<li key={product.id}>{product.name}</li>
))}
</ul>
@trevorblades
trevorblades / user-reducers.js
Created January 9, 2018 22:37
Different options for async or object-based reducers
const user = 'foo';
// option 1: actions first
const defaultState = {
loading: false,
error: null,
properties: user
};
@tb
tb / formikApollo.js
Created August 1, 2017 14:43 — forked from mwickett/formikApollo.js
Formik + Apollo
import React from 'react'
import { withRouter, Link } from 'react-router-dom'
import { graphql, compose } from 'react-apollo'
import { Formik } from 'formik'
import Yup from 'yup'
import FormWideError from '../elements/form/FormWideError'
import TextInput from '../elements/form/TextInput'
import Button from '../elements/form/Button'
import { H2 } from '../elements/text/Headings'
@mwickett
mwickett / formikApollo.js
Last active December 20, 2022 23:00
Formik + Apollo
import React from 'react'
import { withRouter, Link } from 'react-router-dom'
import { graphql, compose } from 'react-apollo'
import { Formik } from 'formik'
import Yup from 'yup'
import FormWideError from '../elements/form/FormWideError'
import TextInput from '../elements/form/TextInput'
import Button from '../elements/form/Button'
import { H2 } from '../elements/text/Headings'
@andrewzey
andrewzey / React Component Methods.jsx
Last active April 11, 2017 20:40
Reusable "Methods" for Functional React Components
import React, { Component } from 'react';
// Class Components
export default class ClassComponent extends Component {
handleClick(event) {
event.preventDefault();
console.log('The link was clicked');
}
render() {
@tschaub
tschaub / .gitignore
Last active January 20, 2023 14:23
OpenLayers + Webpack
/node_modules/
bundle.js
@paulirish
paulirish / what-forces-layout.md
Last active May 23, 2024 14:12
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@chantastic
chantastic / on-jsx.markdown
Last active March 20, 2024 01:03
JSX, a year in

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I led the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can't

@ericelliott
ericelliott / essential-javascript-links.md
Last active May 17, 2024 03:38
Essential JavaScript Links