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
useEffect(() => { | |
async function getDataAxios() { | |
setLoading(true); | |
await axios({ | |
"method": "GET", | |
"url": "https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/get-detail", | |
"headers": { | |
"content-type": "application/octet-stream", |
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
//if stateToCheck is true then render doThisComponent. | |
//if stateToCheck is false, just skip the component. | |
{stateToCheck && <doThisComponent />} |
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 { useRef } from 'react'; | |
function MyFunction() { | |
const titleInputRef=useRef(); | |
const addressInputRef=useRef(); | |
function submitHandler(event){ | |
event.preventDefault(); | |
const enteredTitle = titleInputRef.current.value; | |
const enteredAddress = addressInputRef.current.value; |
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 HookCounter() { | |
const [count, setCount] = useState(initialCount) | |
//why you need prevState | |
const incrementFive = () => { | |
for(let i=0; i <5; i++){ | |
setCount(prevCount => prevCount + 1) | |
} | |
} | |
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
import React from 'react'; | |
function myTest() { | |
const dummyData = [ | |
{id: 1, title: 'Title 1', image: 'www.image.com/1', desc: 'Description 1'}, | |
{id: 2, title: 'Title 2', image: 'www.image.com/2', desc: 'Description 2'}, | |
{id: 3, title: 'Title 3', image: 'www.image.com/3', desc: 'Description 3'} | |
]; | |
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
function getYear() { | |
return new Date().getFullYear() | |
} | |
function Footer() { | |
return ( | |
<footer className="footer bg-dark py-1 text-center"> | |
Copyright © {getYear()} richleach.com. All Rights Reserved. Please don't steal my stuff. | |
</footer> | |
) | |
} |
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 rand = Math.floor(Math.random() * 10)+1 | |
console.log(rand) |
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
//FETCH, JSON, FOREACH & DIV.INNERHTML EXAMPLE | |
//fetch a json file, loop through each value in the json file and print it out to a div on screen | |
//this is the contents of the people.json file that would need to be located in the same directory to work on your machine | |
[ | |
{"name": "John", | |
"age": 20}, | |
{"name": "Mary", | |
"age": 24}, | |
{"name": "Bob", |
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
<!-- copy and paste entire file and open in browser. | |
Simple layout using flexbox to build columns, I always seem to forget how to do this.... | |
--> | |
<html> | |
<head> | |
<title>HTML & CSS</title> | |
<style> | |
body { | |
margin: 0; |