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 Component(props) { | |
| useCallback(() => { | |
| fetch(props.url); | |
| }, [props]); | |
| } |
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
| { | |
| name: "denny" | |
| } |
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 Parent() { | |
| return(<ChildContainer name="Denny" />); | |
| } | |
| function Child({name}) { | |
| return(<div>{name}</div>); | |
| } | |
| const mapStateToProps = state => ({...}); | |
| const mapDispatchToProps = (dispatch, ownProps) => ({...}); |
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
| import { fetchData } from './utils'; | |
| export function CatFacts({ id }) { | |
| const [data, setData] = useState(); | |
| useEffect(() => { | |
| fetchData(id, setData) | |
| }, [id, setData]); | |
| return <div>Cat Fact: {data}</div>; |
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 App() { | |
| const [index, setIndex] = useState(0); | |
| const notMemoized = () => { | |
| console.log("Rendered no callback"); | |
| }; | |
| const memoized = useCallback(() => console.log("Rendered callback"), []); | |
| return ( | |
| <div className="App"> |
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
| export function CatFacts({ id }) { | |
| const [data, setData] = useState(); | |
| useEffect(() => { | |
| const proxyUrl = "https://cors-anywhere.herokuapp.com/"; | |
| const targetUrl = `https://cat-fact.herokuapp.com/facts/${id}`; | |
| fetch(proxyUrl + targetUrl) | |
| .then(response => response.json()) | |
| .then(facts => { | |
| setData(facts.text); | |
| }); |
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 ExampleComponent({url}) { | |
| const fetchData = useCallback(() => { | |
| // fetch call here | |
| }, [url]); | |
| useEffect(() => fetchData(), [fetchData]); | |
| return (<div></div>); | |
| } |
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 RefEq() { | |
| const A = () => { return 1 }; | |
| const B = A; | |
| const C = () => { return 1 }; | |
| } | |
| // A === B | |
| // C !== A |
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 eq() { | |
| let A = 'hi'; | |
| let B = A; | |
| let A = 'bye' | |
| } | |
| // A === 'bye' | |
| // B === 'hi' |
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 ValueEq() { | |
| let A = 'hello'; | |
| const B = 'goodbye'; | |
| const C = 'hello'; | |
| A = 'hi'; | |
| } | |
| // A === 'hi' | |
| // B === 'goodbye' | |
| // C === 'hello' |
NewerOlder