Skip to content

Instantly share code, notes, and snippets.

View ctrlplusb's full-sized avatar
📢

Sean Matheson ctrlplusb

📢
View GitHub Profile
@lawrencecchen
lawrencecchen / $.ts
Last active April 11, 2024 04:23
next-auth with remix
// app/routes/api/auth/$.ts
import NextAuth from "~/lib/next-auth/index.server";
export const { action, loader } = NextAuth({
providers: [
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
}),
],
@edmundhung
edmundhung / Progress.tsx
Last active March 14, 2023 15:25
Setting up a global loading indicator in Remix
import type { ReactElement, MutableRefObject } from 'react';
import { useEffect, useRef } from 'react';
import { useTransition } from 'remix';
export function useProgress(): MutableRefObject<HTMLElement> {
const el = useRef<HTMLElement>();
const timeout = useRef<NodeJS.Timeout>();
const { location } = useTransition();
useEffect(() => {
@lukeshumard
lukeshumard / helper.js
Created October 2, 2019 10:05
Getting @now/node helpers with tests
const micro = require('micro');
// taken directly from
// https://github.com/zeit/now-builders/blob/f67480a98ac461dc2fe6bb27e8a4ea86e9b6b60a/packages/now-node/src/helpers.ts#L47-L60
function queryParser({ url = '/' }) {
const { URL } = require('url');
// we provide a placeholder base url because we only want searchParams
const params = new URL(url, 'https://n').searchParams;
@sebmarkbage
sebmarkbage / WhyReact.md
Created September 4, 2019 20:33
Why is React doing this?

I heard some points of criticism to how React deals with reactivity and it's focus on "purity". It's interesting because there are really two approaches evolving. There's a mutable + change tracking approach and there's an immutability + referential equality testing approach. It's difficult to mix and match them when you build new features on top. So that's why React has been pushing a bit harder on immutability lately to be able to build on top of it. Both have various tradeoffs but others are doing good research in other areas, so we've decided to focus on this direction and see where it leads us.

I did want to address a few points that I didn't see get enough consideration around the tradeoffs. So here's a small brain dump.

"Compiled output results in smaller apps" - E.g. Svelte apps start smaller but the compiler output is 3-4x larger per component than the equivalent VDOM approach. This is mostly due to the code that is usually shared in the VDOM "VM" needs to be inlined into each component. The tr

@rimatla
rimatla / TSLInt-Prettier-CreateReactApp-TypeScript-setup.md
Last active July 16, 2023 11:24
Create React App + TypeScript Linting with TSLint and Prettier setup on VSCode

Ps: The current setup was done on 01-04-19

Project Dependency Versions at the time 👇

  "react": "^16.7.0",
  "react-dom": "^16.7.0",
  "react-scripts": "2.1.3",
  "typescript": "^3.2.2"
  "tslint": "^5.12.0",
  "tslint-config-prettier": "^1.17.0",
@cecilemuller
cecilemuller / launch.json
Last active March 14, 2024 11:31
Run ts-node in VSCode Debugger
{
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
@ManasJayanth
ManasJayanth / canvas-immediate.js
Created April 19, 2017 05:50
Canvas Immediate mode rendering using React
import type { HostConfig, Reconciler } from 'react-fiber-types';
import type { ReactNodeList } from 'react-fiber-types/ReactTypes';
import DOMPropertyOperations from './DOMPropertyOperations';
import type {
Props,
Container,
Instance,
TextInstance,
OpaqueHandle,
@mzgoddard
mzgoddard / 00.script-async-attr-support-plugin.js
Created November 16, 2016 19:34
Plugin brainstorm to support async attribute use on script tags with webpack.
function ScriptAsyncAttrSupportPlugin() {}
module.exports = ScriptAsyncAttrSupportPlugin;
ScriptAsyncAttrSupportPlugin.prototype.apply = function(compiler) {
compiler.plugin('this-compilation', function(compilation) {
compilation.mainTemplate.plugin('bootstrap', function(source) {
return this.asString([
source,
'',
@srdjan
srdjan / 100+ different counter apps...
Last active February 19, 2024 22:41
100+ different js counter apps...
100+ different js counter apps...

Notes

  • This code handles any JS runtime error during rendering React components. Without this handling, once an error occurs, whole component tree is damaged and can't be used at all. With this handling, nothing will be rendered in production environment (error span in dev env.) + in production the error is logged to Sentry (if you are not using it just delete related code)
  • This is basicaly a workaround for proposed feature in React core - described in Issue: facebook/react#2461
  • Works for all variants of Component creation - React.createClass, extending React.Component and also stateless functional components.
  • To get this work, just put this snippet into your entry js file. Then it will work in whole application.
  • Also supporting React Hot Reload!
  • If you find this useful, please retweet https://twitter.com/Aldredcz/status/744650159942995968 :)

Ideas

  • specify custom error renderer (global / per component, e.g. by implementing method renderOnError() in a comp