Skip to content

Instantly share code, notes, and snippets.

View jimode's full-sized avatar
🎯
Focusing

Jimi Odeyemi jimode

🎯
Focusing
View GitHub Profile
@jimode
jimode / index.html
Last active August 31, 2018 23:11
Shorthand for creating object literals - JS Bin// source https://jsbin.com/siqocem
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@jimode
jimode / context-and-localstorage-using-hooks.js
Last active October 8, 2024 05:58
Providing Context and Local Storage Using Hooks
// Providing Context
// ==================
import React, {useState, useEffect} from "react"
const Context = React.createContext()
function ContextProvider({children}) {
const [allPhotos, setAllPhotos] = useState([])
const [cartItems, setCartItems] = useState([])
// Object.values().filter(Boolean)
// -------------------------------
// Video: https://courses.wesbos.com/account/access/5f69bb13ebaa134ef228e80e/view/455624835
// Filter undefinded toppings out
const tops = Object.values(toppings).filter(topping => topping !== undefined)
// can also be written as:
const tops = Object.values(toppings).filter(Boolean)
// e.g Boolean(undefined) => will return false
// e.g Boolean(0) => will return false