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 a = [1,2,3]; | |
// Remove Elements from index | |
const index = 1; | |
const b = [ ...a.slice(0, index), ...a.slice(index + 1, a.length), ]; | |
console.log('a',a); | |
console.log('b',b); | |
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 TrendingRepo() { | |
const [repos, setRepos] = React.useState([]); | |
const debounceOnChange = React.useCallback(debounce(onChange, 400), []); | |
function onChange(value) { | |
fetch(`https://github-trending-api.now.sh/repositories?language=${value}`) | |
.then(res => res.json()) | |
.then(res => setRepos(res)); | |
} |
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 debounceOnChange = React.useCallback(debounce(onChange, 400), []); |
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 debounceOnChange = debounce(onChange, 400); |
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 debounce(func, wait) { | |
let timeout; | |
return function(...args) { | |
const context = this; | |
if (timeout) clearTimeout(timeout); | |
timeout = setTimeout(() => { | |
timeout = null; | |
func.apply(context, args); | |
}, wait); | |
}; |
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
Browser | Chrome and Firefox | All | |
---|---|---|---|
Axios | Yes | Yes | |
fetch | Yes | No | |
whatwg-fetch | Yes | Yes | |
superagent | Yes | Yes |
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
Features | Axios | whatwg-fetch | superagent | |
---|---|---|---|---|
Promise Support | Yes | Yes | Yes | |
Interceptor | Yes | Not Natively | Not Natively | |
Cancel Request | Yes | Yes | Yes | |
Transform Data | Yes | Not Automatically | Not Automatically | |
Blob Upload | Yes | Yes | Yes | |
Dev Friendly Api | Yes | No (Failed Request do not go to catch block) | Yes |
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
npm | gzip size (kb) | |
---|---|---|
whatwg-fetch | 2.7 | |
reqwest | 3.6 | |
axios | 4.3 | |
superagent | 5.3 | |
request-promise | 65.8 |
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
componentDidUpdate(prevProps, prevState) { | |
if (prevProps.value !== this.props.value) { | |
this.props.changeValue(this.props.value); // action | |
} | |
} |
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
componentWillUpdate(nextProps, nextState) { | |
if (this.props.value !== nextProps.value) { | |
this.props.changeValue(nextProps.value); // action | |
} | |
} |
NewerOlder