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 Locky from 'react-locky'; | |
| const TipLocky = ({ group, toggle, enabled, children }) => ( | |
| <Locky | |
| onEscape={toggle} | |
| noDefault | |
| events={{ | |
| click: 'report-only', | |
| touchend: 'report-only', |
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
| { | |
| // ... | |
| resolve: { | |
| alias: { | |
| 'react': 'preact-compat', | |
| 'react-dom': 'preact-compat', | |
| // Not necessary unless you consume a module using `createClass` | |
| 'create-react-class': 'preact-compat/lib/create-react-class', | |
| // Not necessary unless you consume a module requiring `react-dom-factories` | |
| 'react-dom-factories': 'preact-compat/lib/react-dom-factories' |
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 {remock, createElement} from 'react-mock'; | |
| // Locks on mount. Unlocks on unmount | |
| class LockerInternal extends React.Component { | |
| componentDidMount() { | |
| this.props.locker.lock(); | |
| } | |
| componentWillUnmount() { | |
| this.props.locker.unlock(); |
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
| export const getCustomerName = () => { | |
| // Runs only in the client | |
| return { name: 'Arunoda' } | |
| } |
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 { getCustomerName } from 'api/customer'; | |
| export default class Index extends React.Component { | |
| static getInitialProps ({ req }) { | |
| // calling the same API for client and Server | |
| return getCustomerName(req); | |
| } | |
| } |
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
| export default class Index extends React.Component { | |
| static getInitialProps ({ req }) { | |
| if (process.env.IS_SERVER && req) { // just ONE MORE condition | |
| // !!!NOW!!! Runs only in the server, for sure | |
| .... | |
| } | |
| // Runs only in the client | |
| } | |
| } |
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
| export default class Index extends React.Component { | |
| static getInitialProps ({ req }) { | |
| if (req) { | |
| // Runs only in the server | |
| const faker = require('faker') | |
| const name = faker.name.findName() | |
| return { name } | |
| } | |
| // Runs only in the client |
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
| 'use strict'; | |
| Object.defineProperty(exports, '__esModule', { value: true }); | |
| // the same as before | |
| var PREFIX = '__reactstandin__'; | |
| var REGENERATE_METHOD = PREFIX + 'regenerateByEval'; | |
| var templateOptions = { | |
| placeholderPattern: /^([A-Z0-9]+)([A-Z0-9_]+)$/ |
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 {Phased} from 'recondition'; | |
| // Adds a lovely fade in of the modal | |
| // and a gentle slide-down of the modal content | |
| class Demo extends React.Component { | |
| state = { showDialog: false }; | |
| render() { | |
| return ( | |
| <div> | |
| <button onClick={() => this.setState({ showDialog: true })}> | |
| Show Dialog |
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
| // mouse in mouse case | |
| // solve using "naked enzyme" | |
| wrapper = shallow( | |
| shallow( | |
| <div> | |
| {shallow(<App />) | |
| .find(Mouse) | |
| .prop('render')({ x: 2 })} | |
| </div> |