Skip to content

Instantly share code, notes, and snippets.

View 34fame's full-sized avatar
👨‍💻

Troy Moreland 34fame

👨‍💻
View GitHub Profile
@34fame
34fame / cloudSettings
Last active June 19, 2020 20:01
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-06-19T20:01:34.921Z","extensionVersion":"v3.4.3"}
@34fame
34fame / MountClassComponent.jsx
Last active February 10, 2020 15:47
[Functional vs Class Components] Comparing class components with functional components using Hooks API #react #hooks
import React, { Component } from 'react'
class Foo extends Component {
componentDidMount() {
// startup code here
}
componentWillUnmount() {
// cleanup code here
}
@34fame
34fame / App.jsx
Last active February 10, 2020 15:47
[Basic Component] Skeleton of a basic react component #react
import React from 'react'
const App = () => {
return (
<React.Fragment>
<h1>App</h1>
</React.Fragment>
)
}
@34fame
34fame / Refresh.jsx
Created February 10, 2020 15:22
[Asynchronous with Map] How to use Async and Await with Array.prototyp.map() #react
async function refresh() {
setLoading(true)
let items = [array of ids]
// getItem is an external, asynchronous call
const call = async itemId => {
return getItem({ id: itemId })
}
// the key here is the 'Promise.all'
@34fame
34fame / .env
Created February 10, 2020 15:40
[Display package version in app] Make the version tag in package.json available within your application #javascript #react
REACT_APP_VERSION=$npm_package_version
REACT_APP_NAME=$npm_package_name
@34fame
34fame / App.jsx
Last active February 10, 2020 15:46
[Material UI Themes] Properly setup a MUI theme #react #materialui
import React, { useEffect, useRef, useState } from 'react'
import { makeStyles } from '@material-ui/core/styles'
import AccountCircle from '@material-ui/icons/AccountCircle'
import ExpandMoreIcon from '@material-ui/icons/ExpandMore'
import FavoriteIcon from '@material-ui/icons/Favorite'
import LocationOnIcon from '@material-ui/icons/LocationOn'
import MenuIcon from '@material-ui/icons/Menu'
import RestoreIcon from '@material-ui/icons/Restore'
import {
AppBar,
@34fame
34fame / Login.jsx
Last active February 10, 2020 15:52
[Google Firebase Integration] Integrate React application with Google Firebase #react #firebase #firestore #authentication
import React from 'react'
import { useCookies } from 'react-cookie'
import LoginPage from './login-page'
import {
firebaseAuth,
facebookProvider,
githubProvider,
googleProvider,
@34fame
34fame / App.jsx
Last active February 17, 2020 22:44
[Fetch API] Basic usage of Fetch API #react #fetch
import React, { useEffect, useState } from 'react'
const App = () => {
const url = 'https://jsonplaceholder.typicode.com/todos/1'
const options = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
@34fame
34fame / Moment.jsx
Last active February 22, 2020 18:47
[Scheduling] With iCalendar RRule Standard #javascript #react #datetime
// With rrule & Moment libraries
import React from 'react'
import moment from 'moment'
import { RRule } from 'rrule'
function App() {
const today = new Date(moment.utc().format())
const yesterday = new Date(
moment
.utc()
@34fame
34fame / index.js
Created June 4, 2020 03:00
JWT Authentication Gist
const jwt = require("jsonwebtoken")
const jwt_secret = "42737800"
let user = {
id: "1234",
tenant: "3214",
role: "owner",
}
console.log("user", user)