Skip to content

Instantly share code, notes, and snippets.

JS, GraphQL & React

Jayden Seric jaydenseric

JS, GraphQL & React
View GitHub Profile
jaydenseric /
Created Dec 29, 2019
How to use a Zeit Now subdomain with a Heroku deployment.

How to use a Zeit Now subdomain with a Heroku deployment

In the following steps replace:

  • subdomain with your desired subdomain.
  • with your domain.
  • with your Heroku DNS target (see step 1).
  1. In the Heroku deployment settings, under domains, click “Add domain”. Enter to receive the Heroku DNS target.
  2. In the Heroku deployment settings, under SSL certificates, ensure a certificate is automatically managed. If you don’t do this, attempting to visit in a browser will fail with an SSL error.
jaydenseric / DeferredQuery.jsx
Created Jul 2, 2019
A <DeferredQuery> react component that loads a react-apollo <Query> on demand.
View DeferredQuery.jsx
import React from 'react'
import { Query } from 'react-apollo'
export const DeferredQuery = ({ children, ...props }) => {
const [skip, setSkip] = React.useState(true)
const load = () => setSkip(false)
return (
<Query skip={skip} {...props}>
{args => children({ ...args, load })}
jaydenseric /
Last active Jul 7, 2019
A guide to cache related graphql-react options.

graphql-react options guide

This is a guide to the cache related options for the useGraphQL React hook. The reloadOnLoad and resetOnLoad options also apply to the GraphQL instance method operate.


The defaults are suitable for typical query use, as apps tend to have more queries than mutations.

loadOnMount loadOnReload loadOnReset reloadOnLoad resetOnLoad
jaydenseric / RouteIndicator.mjs
Last active Jul 17, 2020
A route change indicator for Next.js using React hooks.
View RouteIndicator.mjs
import Router from 'next/router'
import React from 'react'
const DONE_DURATION = 250
export const RouteIndicator = () => {
const [loading, setLoading] = React.useState(null)
const [timeoutId, setTimeoutId] = React.useState(null)
const onLoad = () => setLoading(true)
jaydenseric / useIsMounted.mjs
Created Feb 21, 2019
A React hook that tells if the component is mounted.
View useIsMounted.mjs
import React from 'react'
export const useIsMounted = () => {
const ref = React.useRef(false)
const [, setIsMounted] = React.useState(false)
React.useEffect(() => {
ref.current = true
return () => (ref.current = false)
}, [])

event-stream compromise

In October 2018 I investigated why nodemon was emitting a strange deprecation warning, leading to the eventual discovery of the now infamous event-stream npm package compromise. This post shares a unique perspective of the events that unfolded, along with downloadable forensic evidence that has since been purged from the npm registry.

For context, see:

jaydenseric /
Last active May 3, 2020
Setup FastMail in Zeit Now via now-cli.
jaydenseric /
Created Jan 9, 2018
“Responsive iframes without wrappers did you say?” blog post:

Responsive iframes without wrappers did you say?

⚠️ This article is outdated: Don’t use jQuery. Also, this JS technique does not work well when server side rendering.

Responsive images are pretty intuitive; apply max-width: 100% and voila. But what to do about those pesky iframes (video embeds!) whose height does not remain in ratio to width when responding down? The most common technique you will come across dates back years and involves wrappers styled to preserve a hard-coded intrinsic aspect ratio (typically 16:9). Most of the popular scripts such as fitvids.js utilize this technique.

This approach sucks for few reasons:

  1. Wrappers may not play nice with your current setup. Perhaps your videos are added, sized and positioned via a CMS WYSIWYG.
  2. Is ~75 lines of jQuery really necessary?

Fun with Sass & font icons

⚠️ This article is outdated: CSS in JS is far superior to Sass, and font icons are no longer a good idea. Use inline SVG React components and in certain situations plain old .svg files in img tags.

Icon fonts have been been best-practice for a while now. They allow us to use tons of fully styleable cross-browser vector icons with one lightweight HTTP request.

Folk typically use font icons via non-semantic presentational markup such as class="icon icon-happy-face" that should be avoided. With a pinch of Sass you can add icons to elements purely via your stylesheet using easy to remember names, without polluting your markup. Yay!



CSS font smoothing coming to Firefox for Mac

Finally a Mozilla equivalent to -webkit-font-smoothing: antialiased is on the way in Firefox 25: -moz-osx-font-smoothing: grayscale. No more chunky font icons in Firefox for Mac!

Unfortunately we will have to wait a few weeks for this to be useful as Firefox 25 is currently in Aurora phase; according to the rapid release schedule it will be hit Beta September 17 for an October 29 2013 release.

It’s a good idea to begin using it now, IcoMoon has stealthily adopted it already. You can always download Firefox 25 and take it for a spin first.


You can’t perform that action at this time.