Skip to content

Instantly share code, notes, and snippets.

View aaronmcadam's full-sized avatar
🎉
Having fun!

Aaron McAdam aaronmcadam

🎉
Having fun!
View GitHub Profile
@robertwbradford
robertwbradford / react-slots.js
Created August 14, 2020 19:36
React Slot Pattern
const Layout = ({ slot1, slot2 }) => {
return (
<div>
<div>{slot1}</div>
<div>{slot2}</div>
</div>
);
};
const MyApp = () => <Layout slot1={<p>Hello</p>} slot2={<p>world</p>} />;
@jaredpalmer
jaredpalmer / forwardRefWithAs.tsx
Created February 26, 2020 14:56
forwardRefWithAs
import * as React from 'react';
/**
* React.Ref uses the readonly type `React.RefObject` instead of
* `React.MutableRefObject`, We pretty much always assume ref objects are
* mutable (at least when we create them), so this type is a workaround so some
* of the weird mechanics of using refs with TS.
*/
export type AssignableRef<ValueType> =
| {
@karol-majewski
karol-majewski / App.tsx
Last active May 13, 2022 22:18
Generic React components in TypeScript
import * as ReactDOM from 'react-dom';
import { List } from '../components';
ReactDOM.render(
<List
items={[1, 2, 3]}
renderItem={item => <li key={item}>{item.toPrecision(3)}</li>}
wrapper={({ children }) => <ul>{children}</ul>}
/>,
import React, { Suspense, useState } from "react";
import { unstable_createResource as createResource } from "react-cache";
import {
Combobox,
ComboboxInput,
ComboboxList,
ComboboxOption
} from "./Combobox2.js";
function App({ tabIndex, navigate }) {
let UserContext = React.createContext();
class App extends React.Component {
state = {
user: null,
setUser: user => {
this.setState({ user });
}
};
if (typeof window!=='undefined' && navigator.serviceWorker && navigator.serviceWorker.controller) {
let reloadOnNext = false;
let pushState = history.pushState;
history.pushState = function(state, title, url) {
pushState.call(this, state, title, url);
if (reloadOnNext===true) location.reload(true);
};
navigator.serviceWorker.controller.addEventListener('statechange', e => {
@mnsami
mnsami / download_egghead_videos.sh
Last active August 4, 2022 06:27
this script is to download egghead videos using youtube-dl
#!/bin/bash
usage() { echo "usage: --coursename [--coursename \"build-a-react-app-with-redux\"] --type [--type \"courses|lessons\"]" 1>&2; exit 1; }
OPTS=$(getopt -o c:t: --long coursename:,type: -n 'download_egghead_videos.sh' -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$OPTS"
@coryhouse
coryhouse / ReactBindingApproaches.js
Last active May 4, 2019 18:12
React Binding Approaches
// Approach 1: Use React.createClass
var HelloWorld = React.createClass({
getInitialState() {
return { message: 'Hi' };
},
logMessage() {
// this magically works because React.createClass autobinds.
console.log(this.state.message);
},
@jonyardley
jonyardley / Dockerfile
Last active March 3, 2023 21:12
Precompile Ruby on Rails assets with Docker
ARG ASSET_HOST
RUN bundle exec rake ASSET_HOST=${ASSET_HOST} RAILS_ENV=production assets:precompile