- Method ordering
- PropTypes + DefaultProps
- Destructuring from props and state (intent)
- Avoid instance methods (only for things that matters to React)
- Components > render methods (renderElements/renderItems/etc)
- Pure render function (no
window
orMath.random()
) - Containers (connected) vs. Presentational Components (pure)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 { History, Location } from "history"; | |
import { MatchResult } from "path-to-regexp"; | |
import { ReactElement, useContext, useEffect, useState } from "react"; | |
import React from "react"; | |
import { getPathMatch } from "./utils/routing"; | |
export interface RouterContextInterface { | |
history?: History; | |
location?: Location; | |
basePath: string; |
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
.App { | |
text-align: center; | |
} | |
.App-logo { | |
animation: App-logo-spin infinite 20s linear; | |
height: 10vmin; | |
} | |
.App-header { |
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
/** | |
* Instance method anti pattern | |
*/ | |
class MyComponent extends React.Component { | |
computeThatThing() { | |
return this.props.a + this.props.b; | |
} | |
render() { | |
return ( |
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
/** | |
* Dependencies | |
*/ | |
const spawn = require('cross-spawn'); | |
/** | |
* Package.json | |
*/ | |
const packageJson = require('../package.json'); |
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
/** | |
* Dependencies | |
*/ | |
const express = require('express'); | |
const history = require('connect-history-api-fallback'); | |
/** | |
* Environment / configuration | |
*/ | |
const port = process.env.PORT || 3000; |
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
1. Basic Syntax | |
- http://jsbin.com/kixovom/ | |
2. Types and Literals | |
- http://jsbin.com/bagofoc/ | |
3. Truth and Equality | |
- http://jsbin.com/feyepub/ | |
4. Functions | |
- http://jsbin.com/tuzezip/ | |
5. Objects | |
- http://jsbin.com/qukaqig/ |
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 { HTTPFetchNetworkInterface, printAST } from 'apollo-client'; | |
/** | |
* Serialize a object to a query string | |
* @source https://stackoverflow.com/questions/1714786/query-string-encoding-of-a-javascript-object#comment47677757_18116302 | |
*/ | |
function serialize( obj ) { | |
return `?` + Object.keys(obj).map(k => k + `=` + encodeURIComponent(obj[k])).join(`&`); | |
} |
ES2015 has introduced the concept of "classes" in JavaScript.
But be aware - JavaScript classes are just syntactical sugar over JavaScript's existing prototype-based inheritance. The class syntax is not introducing a new object-oriented inheritance model to JavaScript.
JavaScript classes provides simpler and clearer syntax to create objects and deal with inheritance (proceed with caution.. inheritance vs. composition = specialization vs. sharing behavior).
The existing model of prototypal inheritance in JavaScript is based on a special kind of function and the new
keyword, which really just alters how the function behaves regarding what it returns and how it sets up the prototype chain.
NewerOlder