Skip to content

Instantly share code, notes, and snippets.

@rashkov
rashkov / react_hooks.md
Last active September 24, 2020 16:14
Implement React Hooks
const React = /* Implement this */;
  
function HelloComponent(){
    const [myNumber, setMyNumber] = React.useState(0);
    // Simulate rendering data to a screen
    console.log("My number:", myNumber);
    // Simulate rendering a clickable button
    const click = ()=> setMyNumber((num)=> num + 1);
 return click; 
@rashkov
rashkov / block_scoping_for_loops.js
Created February 7, 2017 16:41
printing/console.log from a for loop, block scoping, and ES5 vs ES6
// A simple async function that resolves immediately
let asyncFn = ()=> {
let handlers = (resolve, reject)=> {
resolve();
}
return (new Promise(handlers));
}
// Lack of default block scoping can be confusing. Especially with for loops
// Say, someone might start with this: