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
// 1. Go to https://analytics.twitter.com/ | |
// 2. Keep scrolling till the end until all the stats data is loaded | |
// 3. Right click on the page click on last option "Inspect" a window should open select console from that | |
// 4. copy this entire function | |
function getVal (val) { | |
val=val.replace(/\,/g,''); |
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 from "react"; | |
function Form() { | |
const [state, setState] = React.useState({ | |
firstName: "", | |
lastName: "" | |
}) | |
// same function can be used to update multiple values in the state | |
const handleChange = (evt) => { |
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 App = () => { | |
const [state, setState] = useStateCallback(0); // same API as useState + setState with cb | |
const handleClick = () => { | |
setState( | |
prev => prev + 1, | |
// 2nd argument is callback , `s` is *updated* state | |
// Hey that state is set successfully what do you | |
// want to do, I'm callback your friend 😄 | |
s => console.log("I am called after setState, state:", s) |
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
// time and time end | |
console.time("This"); | |
let total = 0; | |
for (let j = 0; j < 10000; j++) { | |
total += j | |
} | |
console.log("Result", total); | |
console.timeEnd("This"); | |
// Memory |
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, { useState, useEffect } from "react"; | |
import ReactDOM from "react-dom"; | |
import "./styles.css"; | |
function GithubCommit() { | |
const [page, setPage] = useState(1); | |
const [commitHistory, setCommitHistory] = useState([]); | |
const [isLoading, setIsLoading] = useState(true); |
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 from "react"; | |
import ReactDOM from "react-dom"; | |
import "./styles.css"; | |
class GithubCommit extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
commitHistory: [], |
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
// Method to addProductToCart | |
<div> | |
<button | |
onClick={context.addProductToCart.bind(this, product)} | |
> | |
Add to Cart | |
</button> | |
</div> | |
// Method to removeProductFromCart |
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'; | |
import ShopContext from './shop-context'; | |
class GlobalState extends Component { | |
state = { | |
products: [ | |
{ id: 'p1', title: 'React 16 Sticker + T-shirt', price: 29.99 }, | |
{ id: 'p2', title: 'Vue.js T-shirt', price: 9.99 }, | |
{ id: 'p3', title: 'Angular T-shirt', price: 8.99 }, |
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 ShopContext from '../context/shop-context' | |
class CartPage extends Component { | |
static contextType = ShopContext | |
componentDidMount() { | |
// Some advantage of static contextType: We can now also access Context in the rest of the component | |
console.log(this.context) | |
} |
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'; | |
import ShopContext from '../context/shop-context'; | |
import Navigation from '../components/navigation'; | |
import './product.css'; | |
class ProductsPage extends Component { | |
render() { | |
return ( | |
<ShopContext.Consumer> | |
{context => ( |
NewerOlder