Skip to content

Instantly share code, notes, and snippets.

View robertgonzales's full-sized avatar

Robert Gonzales robertgonzales

View GitHub Profile
@robertgonzales
robertgonzales / await-all.js
Created January 11, 2018 23:02
Promise.all using only async await.
const delay = ms => new Promise(r => setTimeout(r, ms))
async function AwaitAll() {
try {
const promises = [
delay(1000),
delay(250),
delay(500),
]
for (let p of promises) await p
@robertgonzales
robertgonzales / 1-helloworld.html
Last active September 14, 2018 16:38
React in the browser, no build step necessary.
<html>
<head>
<title>React Hello World</title>
</head>
<body>
<div id="app"></div>
<script src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<script type="text/babel">
@robertgonzales
robertgonzales / App.jsx
Last active March 26, 2020 15:57
How to make a custom Prompt (using getUserConfirmation) for React Router v4
// use Prompt like normal... magic happens in getUserConfirmation
class App extends Component {
render () {
return (
<Router getUserConfirmation={getUserConfirmation}>
{...}
<Prompt
when={formIsHalfFilledOut}
message="Are you sure you want to leave?"
/>

Keybase proof

I hereby claim:

  • I am robertgonzales on github.
  • I am robricgon (https://keybase.io/robricgon) on keybase.
  • I have a public key whose fingerprint is F694 40F4 23C1 1109 3103 DC8A 4FFA 3FD9 09CF 172D

To claim this, I am signing this object:

@robertgonzales
robertgonzales / Frame.js
Created December 12, 2017 03:03
Use React portals to render inside shadow dom and iframes
class Frame extends Component {
componentDidMount() {
this.iframeHead = this.node.contentDocument.head
this.iframeRoot = this.node.contentDocument.body
this.forceUpdate()
}
render() {
const { children, head, ...rest } = this.props
return (