Skip to content

Instantly share code, notes, and snippets.

View pomber's full-sized avatar
🧭
Building @code-hike

Rodrigo Pombo pomber

🧭
Building @code-hike
View GitHub Profile
@pomber
pomber / Presenter.jsx
Created May 11, 2019 15:08
mdx-deck teleprompter
import React from "react"
import { globalHistory } from "@reach/router"
import Zoom from "./Zoom"
import Slide from "./Slide"
import Pre from "./Pre"
import Clock from "./Clock"
// based on https://github.com/streamich/react-use/blob/master/src/useSpring.ts
import { SpringSystem } from "rebound"
import { useState, useEffect } from "react"
@pomber
pomber / __.babelrc
Last active November 26, 2018 18:06
deck-run
{
"presets": ["@babel/preset-react", "@babel/preset-env"]
}
function lazyWithPreload(factory) {
const Component = React.lazy(factory);
Component.preload = factory;
return Component;
}
const StockChart = lazyWithPreload(() => import("./StockChart"));
// somewhere in your component
...
@pomber
pomber / App.jsx
Last active November 20, 2018 00:14
class App extends React.Component {
state = {
selectedStock: null
};
render() {
const { stocks } = this.props;
const { selectedStock } = this.state;
return (
<React.Suspense fallback={<div>Loading...</div>}>
<StockTable
const stockChartPromise = import("./StockChart");
const StockChart = React.lazy(() => stockChartPromise);
@pomber
pomber / __.babelrc
Last active November 15, 2018 19:12
deck-run
{
"presets": ["@babel/preset-react", "@babel/preset-env"]
}
import React from "react";
import StockTable from "./StockTable";
import StockChart from "./StockChart";
class App extends React.Component {
state = {
selectedStock: null
};
render() {
import React from "react";
import ReactDOM from "react-dom";
import fetchWithCache from "./cache";
function Post({ postId }) {
const post = fetchWithCache(
"https://jsonplaceholder.typicode.com/posts/" + postId
);
return (
<div>
import React from "react";
import ReactDOM from "react-dom";
class Post extends React.Component {
state = {
loading: true,
post: null
};
componentDidMount() {
const { postId } = this.props;
function MyComponent(props) {
/* render using props */
}
function areEqual(prevProps, nextProps) {
/*
return true if passing nextProps to render would return
the same result as passing prevProps to render,
otherwise return false
*/
}