Skip to content

Instantly share code, notes, and snippets.

View ernestofreyreg's full-sized avatar
🚢
Just ship it

Ernesto Freyre ernestofreyreg

🚢
Just ship it
  • San Francisco, CA
View GitHub Profile
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
const ChildComponent = forwardRef((props, ref) => {
useImperativeHandle(ref, () => ({
handleAction() {
console.log('Action performed in Child');
}
}));
return <div>Child Component</div>;
let who = ['The dog','My grandma','His turtle','My bird'];
let action = ['ate','peed','crushed','broke'];
let what = ['my homework', 'the keys', 'the car'];
let when = ['before the class','right on time','when I finished','during my lunch','while I was praying', "yesterday"];
function randomIndex (arr) {
return Math.floor(Math.random() * arr.length);
}
// Functional Lenses
//
// A functional lens is an object that contains
// two functions, a getter and a setter.
//
// {
// getter: (obj) => any,
// setter: (obj, value) => obj
// }
//
import { isValidEmail } from 'lib/email'
import { withMongo } from 'lib/mongodb'
import { Db } from 'mongodb'
import { nanoid } from 'nanoid'
import { NextApiRequest, NextApiResponse } from 'next'
import nc from 'next-connect'
interface User {
id: string
email: string
import { Db, MongoClient, MongoClientOptions } from 'mongodb'
const MONGODB_URI = process.env.MONGO_DB_URL
const MONGODB_DB = process.env.MONGO_DB_NAME
let cached = global.mongo
if (!cached) {
cached = global.mongo = { conn: null, promise: null }
}
import * as React from 'react'
import { NextPage } from 'next'
import { Container } from '@material-ui/core'
import { SubscribeHero } from 'components/SubscribeHero/SubscribeHero'
import { secureLoader, useAPIPost } from 'lib/api'
import useSWR from 'swr'
import { SubscriptionList, EmailSubscription } from 'components/SubscriptionList'
const URL = '/api/subscriptions'
import * as React from 'react'
import axios, { AxiosError } from 'axios'
export const useLoading = (): [boolean, (aPromise: Promise<any>) => any] => {
const [isLoading, setState] = React.useState<boolean>(false)
const mount = React.useRef(false)
React.useEffect(() => {
mount.current = true
return () => {
import React from 'react'
import { ComponentMeta } from '@storybook/react'
import { SubscriptionList } from './SubscriptionList'
import { Container } from '@material-ui/core'
export default {
title: 'Components/SubscriptionList',
component: SubscriptionList,
decorators: [
Story => (
import {
createStyles,
Paper,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Theme,
import { isValidEmail } from 'lib/email'
import { NextApiRequest, NextApiResponse } from 'next'
import nc from 'next-connect'
// THIS IS IN MEMORY STATE
// will reset on every app restart
const subs = []
export default nc<NextApiRequest, NextApiResponse>()
.get(async (req, res) => {