This file contains hidden or 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 curry = fn => { | |
| if (fn.length === 0) { | |
| return fn; | |
| } | |
| const _curry = (...args) => { | |
| if (fn.length <= args.length) { | |
| return fn.apply(null, args); | |
| } | |
| return _curry.bind(null, ...args); |
This file contains hidden or 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 mergeDeep(...objects) { | |
| // For simplicity, we ignore the cases for Date and Regex | |
| const isObject = obj => obj && typeof obj === 'object'; | |
| return objects.reduce((prev, obj) => { | |
| try { | |
| Object.keys(obj).forEach(key => { | |
| const pVal = prev[key]; | |
| const oVal = obj[key]; |
This file contains hidden or 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 current; | |
| return function (...args) { | |
| clearTimeout(current); | |
| current = setTimeout(() => func.apply(this, args), wait); | |
| } | |
| } | |
| // The message, 'Function is actually invoked', will be printed 1 second after the browser window stops resizing. | |
| window.addEventListener('resize', debounce(()=>console.log('Function is actually invoked'), 1000)); |
This file contains hidden or 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 throttle(func, limit) { | |
| let lastFunc; | |
| let lastRan; | |
| return function(...args) { | |
| if (!lastRan) { | |
| func.apply(this, args) | |
| lastRan = Date.now(); | |
| } else { | |
| clearTimeout(lastFunc) | |
| lastFunc = setTimeout(() => { |
This file contains hidden or 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 App extends React.Component { | |
| constructor(props) { | |
| super(props) | |
| this.state = { | |
| value: 'highlight and copy me' | |
| } | |
| this.textInput = React.createRef(); | |
| console.log(this.textInput); | |
| this.handleClick = this.handleClick.bind(this); | |
| } |
This file contains hidden or 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 App = () => { | |
| const [value, setValue] = React.useState('highlight and copy me'); | |
| const textInput = React.useRef(); | |
| const handleClick = () => { | |
| textInput.current.select(); | |
| document.execCommand('copy'); | |
| } | |
| return ( |
This file contains hidden or 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 App = () => { | |
| ... | |
| const mounted = React.useRef(true); | |
| React.useEffect(() => { | |
| if (mounted.current) { | |
| some setState commands | |
| } | |
| return () => { |
This file contains hidden or 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 App extends React.Component { | |
| constructor(props) { | |
| super(props) | |
| this.state = { | |
| value: 'highlight and copy me' | |
| } | |
| this.handleClick = this.handleClick.bind(this); | |
| } | |
| handleClick() { |
This file contains hidden or 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 App = () => { | |
| const [value, setValue] = React.useState('highlight and copy me'); | |
| let textInput; | |
| const handleClick = () => { | |
| textInput.select(); | |
| document.execCommand('copy'); | |
| } | |
| return ( |
This file contains hidden or 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 MyTextInput = (props) => { | |
| return ( | |
| <input {...props}/> | |
| ); | |
| }; | |
| const App = () => { | |
| const [value, setValue] = React.useState('highlight and copy me'); | |
| const textInput = React.useRef('initialRef'); | |
OlderNewer