Method | Side effects1 | State updates2 | Example uses |
---|---|---|---|
Mounting | |||
componentWillMount |
✓ | Constructor equivalent for createClass |
|
render |
Create and return element(s) | ||
componentDidMount |
✓ | ✓ | DOM manipulations, network requests, etc. |
Updating | |||
componentWillReceiveProps |
✓ | Update state based on changed props |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @flow */ | |
import React, { Component } from 'react' | |
import { ContentBox, ContentBoxHeader, ContentBoxParagraph } from '../demo/ContentBox' | |
import Immutable from 'immutable' | |
import InfiniteLoader from './InfiniteLoader' | |
import FlexTable from '../FlexTable/FlexTable' | |
import FlexColumn from '../FlexTable/FlexColumn' | |
function noop () {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import now from 'performance-now'; | |
import raf from 'raf'; | |
import { Component, PropTypes } from 'react'; | |
export default class Transition extends Component { | |
static propTypes = { | |
active: PropTypes.bool.isRequired, | |
children: PropTypes.func.isRequired, | |
duration: PropTypes.number.isRequired, | |
fromValue: PropTypes.number.isRequired, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>js-search indexing</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> |
Ever wonder why a particular website is showing a development build icon for React DevTools? Here's how you can find out!
First copy/paste this well-annotated DevTools build-type-checker function into your browser console so you can run it.
Next, execute the following line in your developer console:
console.log(__REACT_DEVTOOLS_GLOBAL_HOOK__._renderers);
If React is present on the page, you'll see something like:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hasLabelProperty = path => | |
path.node.value.expression.properties.find( | |
property => property.key.name === "label" | |
); | |
const isGlamorAttribute = path => { | |
return path.node.name.name === "css"; | |
}; | |
const getParentComponentName = path => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createLittleKeyPool() { | |
const availableKeys = []; | |
const inUseKeys = []; | |
let previousCycle = null; | |
let keyCounter = 0; | |
function releaseKeys({ startIndex, stopIndex }) { | |
if (previousCycle !== null) { | |
const { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright (c) 2013-present, Facebook, Inc. | |
* | |
* @emails react-core | |
*/ | |
'use strict'; | |
import React, {Component} from 'react'; | |
import ReactDOM from 'react-dom'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is an advanced example! It is not intended for use in application code. | |
// Libraries like Relay may make use of this technique to save some time on low-end mobile devices. | |
// Most components should just initiate async requests in componentDidMount. | |
class ExampleComponent extends React.Component { | |
_hasUnmounted = false; | |
state = { | |
externalData: null, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is an example of how to fetch external data in response to updated props, | |
// If you are using an async mechanism that does not support cancellation (e.g. a Promise). | |
class ExampleComponent extends React.Component { | |
_currentId = null; | |
state = { | |
externalData: null | |
}; |