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
let displayNames = ['Joe Doe', 'Jane Doe']; | |
const getSuffix = () => { | |
if (Math.random() * 100 < 50) { | |
return null; | |
} | |
return 'md'; | |
}; | |
displayNames.forEach((name) => { | |
let suffix = getSuffix(); |
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 { initializeApp } from 'firebase/app'; | |
import { getFirestore } from 'firebase/firestore'; | |
import { getStorage } from 'firebase/storage'; | |
const firebaseConfig = { | |
/* Firebase config goes here */ | |
}; | |
const app = initializeApp(firebaseConfig); | |
const db = getFirestore(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
import { useRef } from 'react'; | |
import Image from 'next/image'; | |
import { useSession } from 'next-auth/react'; | |
import { EmojiHappyIcon } from '@heroicons/react/outline'; | |
import { CameraIcon, VideoCameraIcon } from '@heroicons/react/solid'; | |
import { collection, addDoc, serverTimestamp } from 'firebase/firestore'; | |
import { db } from '../firebase'; | |
export default function InputBox() { | |
const { data: session } = useSession(); |
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
// It's important to pass NULL as the default value to useRef Hook since React.useRef can only be NULL or an Element Object. | |
// <div> reference type | |
const divRef = React.useRef<HTMLDivElement>(null); | |
// <button> reference type | |
const buttonRef = React.useRef<HTMLButtonElement>(null); | |
// <br /> reference type | |
const brRef = React.useRef<HTMLBRElement>(null); |
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'; | |
export default function InputBox() { | |
// before render `inputRef` is `null` | |
// after render `inputRef` is an Object with a `current` property | |
const inputRef = useRef<HTMLInputElement>(null); | |
const sendPost = async (e: any) => { | |
// prevent page refresh on submit | |
e.preventDefault(); |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<!-- See Kevin Powell (KP) [https://youtu.be/HJ0-fUJ-2F0] for definitions --> | |
<!-- <head> is our meta data (not visible on page) --> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>HTML Basics</title> | |
</head> |
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
// see YouTube video from Basarat (https://youtu.be/8KIkLPQPt98) | |
// Example 1 - Template Literal Types - Basic | |
let jsStringLiteral: string; | |
jsStringLiteral = 'Hello'; | |
jsStringLiteral = 'World'; | |
let jsTemplateLiteral: `Example: ${string}`; // Okay | |
jsTemplateLiteral = `Example: ${jsStringLiteral}`; // Okay | |
jsTemplateLiteral = `Example: ${3.14}`; // Okay |
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
interface Props { | |
title : string | |
color?: string | |
} | |
const Header = (props : Props) => { | |
return ( | |
<header> | |
<h1 | |
style={{ |
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
// Basic Types | |
let id : number = 5; | |
let company : string = 'Me Inc.'; | |
let isPub : boolean = true; | |
let x : any = 'Hello'; | |
// Arrays | |
let ids : number[] = [1, 2, 3, 4, 5]; | |
// Tuple |