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
FROM node:12.18.3 | |
WORKDIR /usr/src/app | |
COPY package*.json ./ | |
ENV MONGO_URL "mongodb://mongo:27017" | |
ENV DB_NAME points | |
ENV COL_NAME dataPoints |
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
version: "2" | |
services: | |
web: | |
build: | |
context: . | |
dockerfile: Dockerfile | |
container_name: web | |
ports: | |
- "4000:4000" |
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
FROM node:12.18.3 | |
WORKDIR /usr/src/app | |
ENV MESSAGE "Hello from Ben" | |
COPY package*.json ./ | |
RUN npm install |
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 { useState, useRef, forwardRef, useImperativeHandle } from "react"; | |
const ChildOne = forwardRef((props, ref) => { | |
const [count, setCount] = useState(0); | |
useImperativeHandle(ref, () => ({ | |
count, | |
})); | |
const updateCount = () => { |
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 { useState, useMemo } from "react"; | |
const data = [ | |
[93, 64, 60, 28, 17, 24, 36, 9, 47, 11, 80, 45], | |
[87, 76, 66, 20, 18, 71, 5, 22, 36, 48, 28, 99], | |
[3, 71, 62, 59, 22, 15, 33, 19, 13, 98, 98, 42], | |
]; | |
const double = (arr) => { | |
console.log("=> double", Date.now()); |
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 { useState, useMemo } from "react"; | |
const data = [ | |
[93, 64, 60, 28, 17, 24, 36, 9, 47, 11, 80, 45], | |
[87, 76, 66, 20, 18, 71, 5, 22, 36, 48, 28, 99], | |
[3, 71, 62, 59, 22, 15, 33, 19, 13, 98, 98, 42], | |
]; | |
const double = (arr) => { | |
// This shows that the function is being run on each render |
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 { useState, useCallback } from "react"; | |
const CountDisplay = ({ count }) => <h3>Count: {count}</h3>; | |
const CountButton = React.memo(({ updateCount }) => { | |
// Note that this line will now only execute once on initial render! | |
console.log("=> CountButton render", Date.now()); | |
return <button onClick={() => updateCount()}>Increment</button>; | |
}); |
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 { useState } from "react"; | |
const CountDisplay = ({ count }) => <h3>Count: {count}</h3>; | |
const CountButton = ({ updateCount }) => { | |
// Note that this line will fire every time, | |
// showing us that an unneeded re-render has occurred. | |
console.log("=> CountButton render", Date.now()); | |
return <button onClick={() => updateCount()}>Increment</button>; |
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
// Find the min of an array | |
const a = [3, 8, 2, 99, 1, 42, 23] | |
Math.min.apply(Math, a) | |
// How to turn an array into an object | |
const a = [3, 8, 2, 99, 1, 42, 23] | |
const b = a.reduce((a, b, i) => { | |
const obj = {} | |
obj[i] = b |
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 { useRouter } from 'next/router' | |
const Post = ({ post }) => { | |
const router = useRouter() | |
if (router.isFallback) { | |
return <div>Loading...</div> | |
} | |
return ( |