This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ConfigInterface, useSWRInfinite } from 'swr' | |
import { useMemo, useCallback, useRef } from 'react' | |
import last from 'lodash.last' | |
import get from 'lodash.get' | |
type PageKeyMaker<Page, Key extends any[]> = ( | |
index: number, | |
previousPageData?: Page | |
/** | |
* Mutable ref object. Set this to `true` before the request and `false` afterwards if the request is fetching more. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import useNativeSWR from 'swr' | |
import { useRef } from 'react' | |
// inspired by https://github.com/vercel/swr/discussions/456 | |
export default function useSWR(key, fetcher, options = {}) { | |
const { cachePolicy, ...opts } = options | |
const random = useRef(new Date()) | |
return useNativeSWR( | |
() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////////////////////////////// | |
// Create a directory called "pages" next to | |
// this file, put markdown files in there, and | |
// then run: | |
// | |
// ``` | |
// $ node build.mjs | |
// ``` | |
// | |
// Then deploy the "build" directory somewhere. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-inner-declarations */ | |
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment'; | |
let isEnabled = false; | |
if (canUseDOM) { | |
/** | |
* Web browsers emulate mouse events (and hover states) after touch events. | |
* This code infers when the currently-in-use modality supports hover | |
* (including for multi-modality devices) and considers "hover" to be enabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Animated, { | |
useSharedValue, | |
withTiming, | |
useAnimatedStyle, | |
Easing, | |
makeRemote, | |
withSpring, | |
processColor, | |
useValue, | |
delay as RDelay, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import useScrollRestoration from "utils/hooks/useScrollRestoration"; | |
const App = ({ Component, pageProps, router }) => { | |
useScrollRestoration(router); | |
return <Component {...pageProps} />; | |
}; | |
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
import { TouchableOpacity, Text } from "react-native"; | |
import { Notifications } from "expo" | |
import { useNotification } from "./useNotification"; | |
const sendNotification = async () => await Notifications.presentLocalNotificationAsync( | |
{ | |
title: "Notified!", | |
body: "Hello, World!", | |
data: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useRef, useEffect, memo } from 'react' | |
import { useRouter } from 'next/router' | |
const ROUTES_TO_RETAIN = ['/dashboard', '/top', '/recent', 'my-posts'] | |
const App = ({ Component, pageProps }) => { | |
const router = useRouter() | |
const retainedComponents = useRef({}) | |
const isRetainableRoute = ROUTES_TO_RETAIN.includes(router.asPath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Target state | |
var tx = 0; | |
var ty = 0; | |
var scale = 1; | |
function visualiseTargetState() { | |
box.style.transform = `translate(${tx}px, ${ty}px) scale(${scale})`; | |
} | |