Skip to content

Instantly share code, notes, and snippets.

@jakst
jakst / collapsible.tsx
Created June 27, 2019 18:02
useCollapsible
import React, { useContext } from 'react'
import { animated, useSpring } from 'react-spring'
import styled from 'styled-components'
import CleanButton from '../elements/clean-button'
import useMeasure from '../hooks/measure.hook'
import useToggle from '../hooks/toggle.hook'
type Props = {
header: React.ReactNode
children: React.ReactNode
@jakst
jakst / delayed-render.hoc.tsx
Last active June 17, 2019 12:09
React delayed rendering HOC. Delays rendering of component with 0 to maxDelay milliseconds (default 0 to 1000 ms)
function delayRendering<MyProps>(Component: React.FC<MyProps> | React.ComponentClass<MyProps>, maxDelay = 1000) {
// We need to memoize the original component so that it
// does not rerender every time the parent rerenders
const MemoizedComponent = React.memo(function(props: MyProps) {
return <Component {...props} />
})
return (props: MyProps) => {
const [previousProps, setPreviousProps] = useState(props)
@jakst
jakst / index.js
Created January 4, 2019 15:15
Express example with failing OPTIONS call to known endpoint
const express = require("express");
const app = express();
app.get("/ping", (req, res) => {
res.send("pong");
});
app.use(function(req, res, next) {
res.status(404).send("Nope");
});