Skip to content

Instantly share code, notes, and snippets.

View chaance's full-sized avatar
🏄‍♂️
Out there

Chance Strickland chaance

🏄‍♂️
Out there
View GitHub Profile
@chaance
chaance / use-map.ts
Created September 21, 2024 09:10
useMap / useSet
import * as React from 'react';
export function useMap<K = unknown, V = unknown>(
initialEntries?: readonly (readonly [K, V])[] | null,
): IMap<K, V> {
const [map, setMap] = React.useState(() => new Map(initialEntries));
return {
raw: map,
clear: React.useCallback(() => {
setMap((map) => {
@chaance
chaance / keymap.json
Created July 6, 2024 21:09
Zed stuff
[
{
"context": "Editor",
"bindings": {
"escape": "editor::Cancel",
"backspace": "editor::Backspace",
"shift-backspace": "editor::Backspace",
"ctrl-h": "editor::Backspace",
"delete": "editor::Delete",
"ctrl-d": "editor::Delete",
@chaance
chaance / lol.md
Created July 5, 2023 22:39
Musings on CSS editor extension idea

Given the following structure:

| global.css
| lib
| -- utils.css
| ui
| -- button.css
| -- button.tsx
| -- text.css
@chaance
chaance / lol.md
Created July 5, 2023 22:39
Musings on CSS editor extension idea

Given the following structure:

| global.css
| lib
| -- utils.css
| ui
| -- button.css
| -- button.tsx
| -- text.css
@chaance
chaance / carousel.tsx
Created May 17, 2023 01:25
Low-level carousel API ideas
@chaance
chaance / root.tsx
Created March 11, 2023 00:32
Remove trailing slashes to URL via redirect in Remix
import { redirect, type LoaderArgs } from "@remix-run/node";
export async function removeTrailingSlashes(request: Request) {
let url = new URL(request.url);
if (url.pathname.endsWith("/") && url.pathname !== "/") {
throw redirect(url.pathname.slice(0, -1) + url.search);
}
}
export async function loader({ request }: LoaderArgs) {
@chaance
chaance / use-prompt.jsx
Last active August 5, 2024 18:44
Example implementation of `usePrompt` and React Router v5's `<Prompt>` with `unstable_useBlocker`
/**
* ------------------------------------------------------------------------------
* IMPORTANT UPDATE:
* This is *not* a complete implementation and I do not suggest using it!. This
* was primarily an experiment to determine whether or not a decent blocking
* hook could be implemented in userland, and the answer we came up with is NO.
*
* Luckily we added `usePrompt` (behind an `unstable_` flag) back to React Router
* a few versions ago! It's not documented [and I'm no longer on the team, so I
* probably won't try to do anything about that], but you can see it in source.
@chaance
chaance / use-transition.ts
Last active January 10, 2023 02:00
Convert `useNavigation` to `useTransition`
import * as React from "react";
import { useNavigation, type Navigation } from "@remix-run/react";
export function useTransition(): Transition {
let navigation = useNavigation();
return React.useMemo(
() => convertNavigationToTransition(navigation),
[navigation]
);
@chaance
chaance / social-img-route.ts
Created November 10, 2022 18:58
Remix resource route for generating dynamic social images with Cloudinary transforms
import type { LoaderArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
import {
getSocialImageUrl,
getImageContentType,
} from "~/utils.server";
export async function loader({ request }: LoaderArgs) {
let requestUrl = new URL(request.url);
@chaance
chaance / changesets.md
Created October 31, 2022 11:50
Changesets GitHub Review (2022/10/31)

Changesets GitHub Review (2022/10/31)

General questions/notes

  • Question: is it a problem for you all to have lots of old/stale open issues lingering around? I personally find that distracting if things aren't actionable, but if that's not a problem for you feel free to ignore some of this.
  • There are lots of good ideas and feature requests, but I'm curious if you all have discussed priorities for new features or a future version.
  • There are some open issues marked "good first issue" that seem pretty simple I might try and tackle. No question here, just a note!

Easy to close issues