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 / App.jsx
Created May 15, 2022 14:42
Basic React exercise
import { useState, useEffect } from "react";
import blogs from "./blogs";
import "./App.css";
// Task:
// - Update the `useBlogPosts` hook to "fetch" blog posts using the
// `getBlogPosts` function. It should return blog posts (if we have them), an
// error (if it exists) and the loading state.
// - Update the `Blog` component to render each blog post once they have been
// fetched. Make sure you handle error cases if the fetch fails or if we

Remix styling roadmap

Up to this point, Remix has taken a hands-off approach to styling with anything other than plain CSS. This made sense in the beginning because we took a very different approach to CSS than most other component-driven frameworks. We want users to actually understand how CSS actually makes it to the page, and following the path of other frameworks means introducing some magic that obscures that.

That being said, it's not a viable strategy long-term to stay agnostic about

@chaance
chaance / route-announcement.js
Created November 21, 2021 16:02
Remix route transition announcements
import * as React from "react";
import { useLocation, useTransition } from "remix";
function RouteAnnouncement({ getTitle = defaultGetTitle }) {
let location = useLocation();
let transition = useTransition();
let liveRegionRef = React.useRef(null);
React.useEffect(() => {
liveRegionRef.current = document.createElement("div");
@chaance
chaance / postcss-simple-scoper.js
Last active October 12, 2021 02:53
This was the result of a brainfart I had today. I wanted a PostCSS plugin that game me some *very simple* scoping capabilities, and nothing I found quite did what I wanted. Yet to thoroughly test this, but putting it here for now so I don't forget about it.
const DIRECTIVES = [
/**
* If there is currently a local scope or no scope, the :root directive will
* revert to using only the top-level scope if one is defined.
*
* @example
*
* @simple-scope;
*
@chaance
chaance / reset.css
Created October 5, 2021 22:38
Go-to resets for new projects
html {
box-sizing: border-box;
tab-size: 4;
font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
line-height: 1.15;
-webkit-text-size-adjust: 100%;
}
*,
@chaance
chaance / composer.json
Created September 2, 2021 04:09
Example composer.json for a WordPress project using PHP Codesniffer
{
"name": "blah/blah",
"type": "wordpress-theme",
"authors": [
{
"name": "Chance Strickland",
"email": "[email protected]"
}
],
"require": {
@chaance
chaance / example.ts
Created August 12, 2021 03:39
Merge discriminated union props for better easier destructuring
type SomeProps =
| { action: "START" }
| { action: "STOP"; time: number }
| { action: "PAUSE"; time: number; ref: { current: any } };
function useExample(props: SomeProps) {
let {
action, // "START" | "STOP" | "PAUSE"
time, // number | undefined,
ref // { current: any } | undefined
@chaance
chaance / useAccessibleRouting.js
Last active August 9, 2021 18:09
More accessible client-side routing with React Router. Experimental code!
function useAccessibleRouting(skipLinkRef) {
let location = useLocation();
let liveRegionRef = React.useRef();
React.useEffect(
/**
* Create a live region that will be used to announce route changes when the
* user navigates. This hook should be called from the root App component,
* so this should be created and appended to the DOM only once.
*/
@chaance
chaance / weird.tsx
Created May 27, 2021 22:18
Inferred link props with TS template literal types
type LinkProps<T extends { href: any }> = T extends { href: infer U }
// If our `href` prop starts with a given substring, we might
// determine that we have an external link and filter internal
// routing-related props. This could just as easily work in reverse!
? U extends `https://${string}` | `http://${string}`
? ExternalLinkProps
: InternalLinkProps
: never;
@chaance
chaance / phony-use-state.ts
Created April 13, 2021 13:57
Phony useState
// For Reference
import * as React from 'react'
import * as ReactDOM from 'react-dom'
const states: any[] = []
let calls = -1
function useState<S>(value: S) {
const call = ++calls