Skip to content

Instantly share code, notes, and snippets.

View tomsoderlund's full-sized avatar

Tom Söderlund tomsoderlund

View GitHub Profile
@tomsoderlund
tomsoderlund / useRouterQueryState.js
Last active August 15, 2023 21:03
Like useState hook, but saves current state in browser search bar (Next.js router query)
// import useRouterQueryState from '../hooks/useRouterQueryState'
// const [myState, setMyState] = useRouterQueryState(propertyName, defaultValue)
import { useState, useEffect } from 'react'
import { useRouter } from 'next/router'
function useRouterQueryState (key, defaultValue) {
const router = useRouter()
// Get initial state from router query or default value
@tomsoderlund
tomsoderlund / App.tsx
Created November 10, 2023 17:24
React Native 2D animation and touch handling with expo-2d-context and expo-gl
import React, { useRef, useCallback, useEffect } from 'react'
import { GestureResponderEvent, PixelRatio } from 'react-native'
import { GLView } from 'expo-gl'
import Expo2DContext, { Expo2dContextOptions } from 'expo-2d-context'
const App = (): React.ReactElement => {
const ctxRef = useRef<Expo2DContext | null>(null)
const pixelRatio = PixelRatio.get()
let originPos = [0, 0]