| 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 hidden or 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 React from 'react' | |
| import Portal from 'react-portal' | |
| class LinkBlock extends React.Component { | |
| constructor (props) { | |
| super(props) | |
| this.state = { | |
| href: this.props.node.data.get('href'), | |
| showingPopup: false, | |
| popup: null, |
This file contains hidden or 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
| module AMS | |
| module V09 | |
| class Serializer < ActiveModel::Serializer | |
| def serializable_hash(adapter_options = nil, | |
| options = {}, | |
| adapter_instance = self.class.serialization_adapter_instance) | |
| object.nil? ? nil : super | |
| end | |
| end |
This file contains hidden or 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 React from 'react' | |
| import Portal from 'react-portal' | |
| import getOffsets from 'positions' | |
| import { findDOMNode } from 'slate' | |
| /** | |
| * No-op. | |
| * | |
| * @type {Function} |
This file contains hidden or 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 { Plugin } from 'uppy'; | |
| export default class ReduxEmitter extends Plugin { | |
| constructor(core, opts) { | |
| super(core, opts); | |
| this.type = 'redux'; | |
| this.id = 'ReduxEmitter'; | |
| this.title = 'Redux Emitter'; | |
| // set default options | |
| const defaultOptions = {}; |
This file contains hidden or 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
| class MyEditor { | |
| onPaste = (_event, paste, state) => { | |
| if (paste.type === "text" && isUrl(paste.text) && state.isCollapsed) { | |
| return ( | |
| state | |
| .transform() | |
| .insertText(paste.text) | |
| .extend(0 - paste.text.length) | |
| .wrapInline({ | |
| type: "link", |
This file contains hidden or 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 React from 'react'; | |
| import Helmet from 'react-helmet'; | |
| import { renderToString, renderToStaticMarkup } from 'react-dom/server'; | |
| import { StaticRouter } from 'react-router-dom'; | |
| import { AsyncComponentProvider, createAsyncContext } from 'react-async-component'; | |
| import asyncBootstrapper from 'react-async-bootstrapper'; | |
| import config from '../../../config'; | |
| import ServerHTML from './ServerHTML'; |
This file contains hidden or 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 from 'react'; | |
| import styled from 'styled-components'; | |
| type GlobalCssValues = 'initial' | 'inherit' | 'unset'; | |
| type WrapValue = 'nowrap' | 'wrap' | 'wrap-reverse' | GlobalCssValues; | |
| type JustifyValue = | |
| | 'center' |
This file contains hidden or 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 express = require('express'); | |
| require('babel-register')({ | |
| ignore: /\/(build|node_modules|.svg)\//, | |
| presets: ['env', 'react-app'] | |
| }); | |
| const universal = require('./universal'); | |
| const app = express(); |
This file contains hidden or 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
| // The `loader` prop is a Dataloader instance | |
| // https://github.com/facebook/dataloader | |
| class Dataloader extends React.Component { | |
| state = {data: null, isLoaded: false}; | |
| componentWillMount() { | |
| this.prefetchData(this.props); | |
| } | |
| componentWillReceiveProps(nextProps) { | |
| if (this.props.id !== nextProps.id || this.props.loader !== nextProps.loader) { | |
| this.setState({isLoaded: false}); |