Skip to content

Instantly share code, notes, and snippets.

View anthonybrown's full-sized avatar
🎯
Focusing

Tony Brown anthonybrown

🎯
Focusing
View GitHub Profile
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 }) {
@bvaughn
bvaughn / index.md
Last active April 17, 2025 15:47
How to use profiling in production mode for react-dom

React recently introduced an experimental profiler API. This page gives instructions on how to use this API in a production release of your app.

Table of Contents

Profiling in production

React DOM automatically supports profiling in development mode for v16.5+, but since profiling adds some small additional overhead it is opt-in for production mode. This gist explains how to opt-in.

@rcugut
rcugut / [GUIDE] macos yarn nvm install.md
Last active July 10, 2023 11:49
GUIDE for mac OS X yarn nvm node install

GUIDE to install yarn, nvm (node) on macOS

last update: Dec 4, 2020

Assumptions:

  • macOS >= 10.14 (Mojave); tested with 10.15 (Catalina)
  • homebrew properly installed
class Example extends React.Component<
Props,
State,
Snapshot
> {
static getDerivedStateFromProps(
nextProps: Props,
prevState: State
): $Shape<State> | null {
// ...
@stevekinney
stevekinney / web-performance.md
Last active January 2, 2025 14:53
Web Performance Workshop

Web Performance

Requirements

Repositories

@kentcdodds
kentcdodds / object.entries.js
Last active November 7, 2020 23:36
Example of using Object.entries
// http://www.dogbreedchart.com
const dogShedding = {
foxhound: 3,
'basset hound': 2,
beagle: 3,
'bernese mountain dog': 1,
poodle: 5,
}
// 🔥🔥
@bvaughn
bvaughn / updating-subscriptions-when-props-change-example.js
Last active March 27, 2022 09:29
Advanced example for manually updating subscriptions in response to props changes in an async-safe way
// This is an advanced example! It is not typically required for application code.
// If you are using a library like Redux or MobX, use the container component provided by that library.
// If you are authoring such a library, use the technique shown below.
// This example shows how to safely update subscriptions in response to props changes.
// In this case, it is important to wait until `componentDidUpdate` before removing a subscription.
// In the event that a render is cancelled before being committed, this will prevent us from unsubscribing prematurely.
// We also need to be careful about how we handle events that are dispatched in between
// `getDerivedStateFromProps` and `componentDidUpdate` so that we don't put stale values into the `state`.
@IbrahimTanyalcin
IbrahimTanyalcin / linkedin help - 20180222 - 1
Last active February 26, 2018 18:08
linkedin help - 20180222 - 1
var obj = {value:3,stop:false}, //assing your value to obj.value every sec etc.
values = [], //array to store values
freq = 500, //frequency of check
result = undefined; //the result of average in the end
function checker(t){ //the function to periodically check
checker.startTime = checker.startTime || t;
if(obj.stop){ //if you set obj.stop to true, you will terminate the check
/*in the end calculate the result
if you want, store the a.length somewhere else
import Ember from 'ember';
import Changeset from '../lib/changeset';
import validatePresence from '../validators/presence';
let model = { foo: 'bar' };
let validations = {
foo: validatePresence()
};
let changeset = new Changeset(model, { validations });