Skip to content

Instantly share code, notes, and snippets.

View kasper573's full-sized avatar

Kasper kasper573

View GitHub Profile
import { pipe, tap } from "wonka";
import { Exchange } from "urql";
import {
IntrospectionListTypeRef,
IntrospectionNamedTypeRef,
IntrospectionQuery,
IntrospectionType,
IntrospectionTypeRef,
Kind,
OperationDefinitionNode,
@kasper573
kasper573 / shouldFor.ts
Last active October 22, 2022 20:51
shouldFor
const disableTimeout = 999999999;
Cypress.Commands.add(
"shouldFor",
(
condition,
requiredDuration,
{
name = "Condition",
interval = 10,
import {
useContext,
useState,
createContext,
useRef,
PropsWithChildren,
} from "react";
import { useInterval } from "../hooks/useInterval";
import { useApi } from "./ApiProvider";
import { AuthTokens } from "../api/types/AuthTokens";
type A = number;
type B = string;
type Lists = {
a: A[];
b: B[];
};
export const selectList = <ListName extends keyof Lists>(
listName: ListName
@kasper573
kasper573 / Form.tsx
Last active November 23, 2020 23:16
React Template Component
import React from "react";
import { createTemplateComponent } from "./createTemplateComponent";
/**
* Form elements displayed as a list by default but with customizable template.
*/
export const Form = createTemplateComponent(
renderElements,
({foo, bar, baz, other}) => (
<ul>
import { EffectCallback, useEffect } from 'react';
export const usePureEffect = <T extends EffectCallbackWithParams>(
effect: T,
...params: Parameters<T>
) => useEffect(() => effect.apply(null, params), params);
type EffectCallbackWithParams = (...args: any) => ReturnType<EffectCallback>;
let slide = document.querySelectorAll('.slideUp');
slide.forEach(function (el) {
el.addEventListener('click', function () {
let parent = el.parentElement;
let links = parent.querySelectorAll('.link');
let rotationTranform = 'rotate(45deg)';
let isRotated = el.style.transform === rotationTranform;
if (!isRotated) {
el.style.transform = rotationTransform;
const container = document.getElementById('container');
const element1 = document.createElement('div');
const element2 = document.createElement('div');
if (element2.classList.contains('specific')) {
container.prepend(element1);
container.prepend(element2);
} else {
container.prepend(element2);
import * as React from 'react';
const hoistNonReactStatic = require('hoist-non-react-statics');
/**
* Decorator to form a HOC that acts like a react context consumer.
* Useful when you want context to be made available in an entire component and not just in render.
*
* Example:
* type MyContextProps = {foo: string};
* const MyContext = createContext<MyContextProps>({foo: 'bar'});