Last active
June 6, 2019 07:01
-
-
Save oakfang/7085c23f2a4582a128a7b000ce6744c4 to your computer and use it in GitHub Desktop.
Black box function
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 blackBox() { | |
var input = [0, 1, 2, 3, 4]; | |
var results = []; | |
for (var i = 0; i < input.length; i++) { | |
results.push( | |
new Promise(function(resolve) { | |
setTimeout(function() { | |
resolve(i); | |
}, 200); | |
}) | |
); | |
} | |
Promise.all(results).then(console.log); | |
} |
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 React, { Component } from "react"; | |
class MyComponent extends Component { | |
state = { | |
valueLength: 0 | |
}; | |
componentDidMount() { | |
this.setState({ valueLength: this.props.value.length }); | |
} | |
componentDidUpdate() { | |
this.setState({ valueLength: this.props.value.length }); | |
} | |
render() { | |
const { valueLength } = this.state; | |
const { value } = this.props; | |
return <p>{value} is {valueLength} chars long</p>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment