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
export class SampleComponent extends React.Component { | |
shouldComponentUpdate(nextProps, nextState) { | |
return !_.isEqual(this.props, nextProps) || | |
!_.isEqual(this.state, nextState); | |
} | |
render() { | |
return <div className={this.props.className}>foo</div>; | |
} | |
} |
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
> console.log.bind(null, 'hi') === console.log.bind(null, 'hi') | |
false | |
> function(){console.log(‘hi');} === function(){console.log(‘hi');} | |
false | |
// New function each time | |
render() { | |
return <MyComponent onClick={() => this.setState(...)} /> | |
} |
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 TodoItem = React.createClass({ | |
deleteItem() { | |
this.props.deleteItem(this.props.index); | |
}, | |
}); |
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
> ['important', 'starred'] === ['important', 'starred'] | |
false |
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
<div> | |
<ComplexForm props={this.props.complexFormProps} /> | |
<ul> | |
<li prop={this.props.items[0]}>item A</li> | |
...1000 items... | |
</ul> | |
</div> |
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
<div> | |
<CustomList items={this.props.items} /> | |
<ComplexForm props={this.props.complexFormProps} /> | |
</div> |
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
getCachedExpensiveComputation() { | |
if (this._cachedSomeProp !== this.prop.someProp) { | |
this._cachedSomeProp = this.prop.someProp; | |
this._cachedComputation = doExpensiveComputation(this.prop.someProp); | |
} | |
return this._cachedComputation; | |
} |
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
class Child extends React.Component { | |
greeting() { | |
return 'hello world'; | |
} | |
} | |
class Parent extends React.Component { | |
render() { | |
return ( | |
<TheChild ref='foo' /> | |
) |
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
/** | |
* Complexity Analysis | |
* push: O(1) | |
* pop: Amortized O(1), Worst-case O(n) | |
* empty: O(1) | |
* peek: O(1) | |
*/ | |
function Queue() { | |
var stack1 = []; | |
var stack2 = []; |
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 isOpening = (s, m) => m[s]; | |
const isClosing = (s, m) => ( | |
Object.values(m).includes(s) | |
); | |
const isValid = (last, s, m) => ( | |
m[last] !== s | |
); | |
const balancedParens = s => { | |
const mapping = { |