Skip to content

Instantly share code, notes, and snippets.

View LikeButton.js
'use strict';
const e = React.createElement;
class LikeButton extends React.Component {
constructor(props) {
this.state = { liked: false };
gaearon /
Last active Sep 21, 2021
Modern JavaScript in React Documentation

If you haven’t worked with JavaScript in the last few years, these three points should give you enough knowledge to feel comfortable reading the React documentation:

  • We define variables with let and const statements. For the purposes of the React documentation, you can consider them equivalent to var.
  • We use the class keyword to define JavaScript classes. There are two things worth remembering about them. Firstly, unlike with objects, you don't need to put commas between class method definitions. Secondly, unlike many other languages with classes, in JavaScript the value of this in a method [depends on how it is called](
gaearon /
Last active Aug 18, 2021
A Gentle Introduction to Prepack, Part 1


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.
View theme_sort_of.json
"editor.fontFamily": "Consolas",
"editor.fontSize": 18,
"editor.lineHeight": 26,
"editor.minimap.enabled": false,
"editor.renderIndentGuides": false,
"editor.renderLineHighlight": "none",
"javascript.validate.enable": false,
// "workbench.colorTheme": (find something that looks like Oceanic Next and put it here)
"window.zoomLevel": -1,
View 16.3-blogpost-signatures.js
class Example extends React.Component<
> {
static getDerivedStateFromProps(
nextProps: Props,
prevState: State
): $Shape<State> | null {
// ...
View hahah.js
* Copyright (c) 2015-present, Facebook, Inc.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
View React 16 JavaScript

JavaScript Environment Requirements

React 16 depends on the collection types Map and Set. If you support older browsers and devices which may not yet provide these natively (eg <IE11), consider including a global polyfill in your bundled application, such as core-js or babel-polyfill.

A polyfilled environment for React 16 using core-js to support older browsers might look like:

import 'core-js/es6/map';
import 'core-js/es6/set';
View Error Handling in React
title author
Error Handling in React 16

As React 16 release is getting closer, we would like to announce a few changes to how React handles JavaScript errors inside components. These changes are included in React 16 beta versions, and will be a part of React 16.

Behavior in React 15 and Earlier

In the past, JavaScript errors inside components used to corrupt React’s internal state and cause it to emit cryptic errors on next renders. These errors were always caused by an earlier error in the application code, but React did not provide a way to handle them gracefully in components, and could not recover from them.


Thanks everyone for participating in the quiz!
Many of you have posted correct answers.

What we know:

A top-level App component returns <Button /> from its render() method.


What is the relationship between <Button /> and this in that Button’s render()?