Skip to content

Instantly share code, notes, and snippets.

View aleclarson's full-sized avatar

Alec Larson aleclarson

View GitHub Profile
@aleclarson
aleclarson / rollup-typescript.md
Last active February 28, 2025 16:13
The best Rollup config for TypeScript libraries

It's 2024. You should use tsup instead of this.


Features

🔥 Blazing fast builds
😇 CommonJS bundle
🌲 .mjs bundle
.d.ts bundle + type-checking

@aleclarson
aleclarson / ssl-dev.patch
Last active July 17, 2020 22:56
Trust all SSL certificates in React Native (in development only)
diff --git a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
index 274f381..3b573dc 100644
--- a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
+++ b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
@@ -108,6 +108,15 @@ - (void)cancelRequest:(NSURLSessionDataTask *)task
#pragma mark - NSURLSession delegate
+#if DEBUG
+- (void)URLSession:(NSURLSession *)session
#import <AppKit/AppKit.h>
// This window becomes main and key when the app loses focus, which ensures
// the "didBecomeKey" and "didBecomeMain" events are posted when they should be.
@interface Nothing : NSWindow <NSWindowDelegate>
- (instancetype)init;
- (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag NS_DESIGNATED_INITIALIZER;
@end
diff --git a/node_modules/react-update-url-on-scroll/lib/Manager.js b/node_modules/react-update-url-on-scroll/lib/Manager.js
index 6e8de9f..7cb49c4 100644
--- a/node_modules/react-update-url-on-scroll/lib/Manager.js
+++ b/node_modules/react-update-url-on-scroll/lib/Manager.js
@@ -18,11 +18,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var defaultConfig = {
affectHistory: false,
- debounce: 100,
keepLastAnchorHash: false,
import { is } from 'is'
import { Lookup } from 'types'
// Reuse one array for all encoding.
const pairs: string[] = []
export function encodeForm(values: Lookup) {
for (const key in values) {
encodePair(key, values[key])
}
@aleclarson
aleclarson / unmount.tsx
Created November 2, 2019 12:49
React controlled unmount
import React from 'react'
import { animated, useSpring } from 'react-spring'
const Example = () => {
const [unmount, isUnmounting] = React.useUnmount()
const { opacity } = useSpring({
// Fade in "opacity" from 0
from: { opacity: 0 },
// Fade out "opacity" to 0 when ready to unmount
function roundToStep(n: number, step: number) {
n = Math.round(n / step) * step
// Determine the number of decimals to round.
let p = 0
if (n % 1) {
const s = String(n)
p = s.length - s.indexOf('.') - 1
}
import { createHook } from './createHook'
class App {
count = 0
increaseCount() {
this.count++
}
decreaseCount() {
this.count--
}
@aleclarson
aleclarson / useSubscriber.jsx
Created August 16, 2019 22:55
useSubscriber: Baked-in hook that lets subscribers notify React when data goes stale
import {useSubscriber} from 'react'
const MyComponent = (props) => {
// Get the current value of an observable
const value = props.value.get()
// Subscribe to the observable in the render phase
useSubscriber(forceUpdate => {
// This code runs immediately, instead of acting like "useEffect"
const unsub = props.value.subscribe(() => {
@aleclarson
aleclarson / CHANGELOG.md
Last active April 10, 2020 17:50
react-spring v9

Changes in v9

  • Animated values are now instances of the SpringValue class, which gives users access to an imperative API for updating a single animated value.
  • The reset and immediate props can now be a key or array of keys, instead of only a function or boolean.
  • The next function passed to async to prop can now be passed any useSpring props, instead of only to values.
  • The useSpring hook now supports a deps array, for updating an animation only when certain values changed.
  • The useTransition hook was rewritten from scratch. (see #809)
  • The useTransition hook now has a ref prop.
  • The new cancel prop stops the current animation and prevents future animations. It can be a boolean, a function, a key, or an array of keys.
  • Delayed updates can be cancelled by the cancel prop or stop method.