Skip to content

Instantly share code, notes, and snippets.

View ricokahler's full-sized avatar
💭
recovering from burnout

Rico Kahler ricokahler

💭
recovering from burnout
View GitHub Profile
@sindresorhus
sindresorhus / esm-package.md
Last active May 7, 2024 08:55
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@alexanderson1993
alexanderson1993 / copyToClipboard.ts
Created January 28, 2021 21:43
A component that copies some text to the clipboard when it is clicked.
import * as React from "react";
const CopyToClipboard:React.FC<{text:string} & React.HTMLAttributes<HTMLButtonElement>> = ({text, ...props}) => {
const copyToClipboard = (event:React.MouseEvent<HTMLButtonElement>, str:string) => {
const el = Object.assign(document.createElement('textarea'),{value:str});
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
@kidunot89
kidunot89 / apollo-client.js
Last active July 10, 2020 05:43
useCartMutations - React Hook that use "@apollo-react-hooks", and "uuid" to bundle WooGraphQL cart mutations in a modular tool.
// Node modules
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache, defaultDataIdFromObject } from 'apollo-cache-inmemory';
import { ApolloLink } from 'apollo-link';
import { onError } from 'apollo-link-error';
import { get, isEmpty } from 'lodash';
// Local imports
import { typeDefs, resolvers } from './schema';