Skip to content

Instantly share code, notes, and snippets.

View kartikag01's full-sized avatar
🎯
Focusing

KARTIK AGARWAL kartikag01

🎯
Focusing
  • Banglore, India
View GitHub Profile
@kartikag01
kartikag01 / slice-magic.js
Created August 26, 2019 07:36
immutable operations on array in javascript
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);
@kartikag01
kartikag01 / TrendingRepo
Created July 24, 2019 05:20
TrendingRepo debounce
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));
}
@kartikag01
kartikag01 / memo debounceOnChange
Created July 24, 2019 04:54
memo debounceOnChange
const debounceOnChange = React.useCallback(debounce(onChange, 400), []);
@kartikag01
kartikag01 / use debounce
Created July 24, 2019 04:29
using debounce
const debounceOnChange = debounce(onChange, 400);
@kartikag01
kartikag01 / debounce.js
Created July 24, 2019 04:24
debounce function in java script
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);
};
@kartikag01
kartikag01 / browser-supper.csv
Last active December 9, 2018 10:45
browser support via libs
Browser Chrome and Firefox All
Axios Yes Yes
fetch Yes No
whatwg-fetch Yes Yes
superagent Yes Yes
@kartikag01
kartikag01 / compare-features-in-libs.csv
Last active December 9, 2018 10:29
compare features in libs
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
@kartikag01
kartikag01 / bundles-size.csv
Last active December 9, 2018 09:36
bundle size for api request npm
npm gzip size (kb)
whatwg-fetch 2.7
reqwest 3.6
axios 4.3
superagent 5.3
request-promise 65.8
@kartikag01
kartikag01 / AfterComponentWillUpdate.jsx
Created August 30, 2018 09:14
AfterComponentWillUpdate
componentDidUpdate(prevProps, prevState) {
if (prevProps.value !== this.props.value) {
this.props.changeValue(this.props.value); // action
}
}
@kartikag01
kartikag01 / BeforeComponentWillUpdate.jsx
Created August 30, 2018 09:13
BeforeComponentWillUpdate
componentWillUpdate(nextProps, nextState) {
if (this.props.value !== nextProps.value) {
this.props.changeValue(nextProps.value); // action
}
}