Skip to content

Instantly share code, notes, and snippets.

@bvaughn
bvaughn / index.md
Last active April 3, 2024 07:41
Interaction tracing with React

This API was removed in React 17


Interaction tracing with React

React recently introduced an experimental profiler API. After discussing this API with several teams at Facebook, one common piece of feedback was that the performance information would be more useful if it could be associated with the events that caused the application to render (e.g. button click, XHR response). Tracing these events (or "interactions") would enable more powerful tooling to be built around the timing information, capable of answering questions like "What caused this really slow commit?" or "How long does it typically take for this interaction to update the DOM?".

With version 16.4.3, React added experimental support for this tracing by way of a new NPM package, scheduler. However the public API for this package is not yet finalized and will likely change with upcoming minor releases, so it should be used with caution.

@gaearon
gaearon / prepack-gentle-intro-1.md
Last active May 3, 2024 12:56
A Gentle Introduction to Prepack, Part 1

Note:

When this guide is more complete, the plan is to move it into Prepack documentation.
For now I put it out as a gist to gather initial feedback.

A Gentle Introduction to Prepack (Part 1)

If you're building JavaScript apps, you might already be familiar with some tools that compile JavaScript code to equivalent JavaScript code:

  • Babel lets you use newer JavaScript language features, and outputs equivalent code that targets older JavaScript engines.
@sebmarkbage
sebmarkbage / The Rules.md
Last active June 6, 2024 16:25
The Rules of React

The Rules of React

All libraries have subtle rules that you have to follow for them to work well. Often these are implied and undocumented rules that you have to learn as you go. This is an attempt to document the rules of React renders. Ideally a type system could enforce it.

What Functions Are "Pure"?

A number of methods in React are assumed to be "pure".

On classes that's the constructor, getDerivedStateFromProps, shouldComponentUpdate and render.

@conorhastings
conorhastings / state-component.js
Last active March 30, 2017 20:36
you can enact most of the behavior of redux with a simple component
/* this lacks subscribe behavior or ability to dispatch from outside of component tree but that is generally not neccesary */
class State extends React.Component {
constructor(props) {
super(props);
this.state = YOUR_INITIAL_STATE;
}
reducer = (action, state, props) => {...newState};
/* setState takes an object of new state as first arg or a function of props and state that returns new state
* which we will use here
* we pass dispatch around and use it similarly to redux dispatch
@conorhastings
conorhastings / doesnotwork.js
Last active March 23, 2016 02:30
Node allows use of const (but not let) outside of strict mode but does not seem to respect block scoping
/*
* In this version without use strict declaration 'SyntaxError: Identifier 'text' has already been declared' is given
*/
const http = require('http');
const hostname = 'localhost';
const port = 2001;
http.createServer((req, res) => {
if (req.url === '/favicon.ico') {
@LeCoupa
LeCoupa / nodejs-cheatsheet.js
Last active June 4, 2024 09:34
Complete Node.js CheatSheet --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
/* *******************************************************************************************
* THE UPDATED VERSION IS AVAILABLE AT
* https://github.com/LeCoupa/awesome-cheatsheets
* ******************************************************************************************* */
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html