This file contains 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 React, { useRef, useEffect } from "react"; | |
function useClickOutside(ref) { | |
useEffect(() => { | |
function handleClickOutside(event) { | |
if (ref.current && !ref.current.contains(event.target)) { | |
alert("Outside click"); | |
} | |
} |
This file contains 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
const crypto = require('crypto'); | |
const base32 = require('hi-base32'); | |
export default function generateSecret(length = 20) { | |
const randomBuffer = crypto.randomBytes(length); | |
return base32.encode(randomBuffer).replace(/=/g, ''); |
This file contains 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
const cheerio = require("cheerio"); | |
const fs = require("fs"); | |
const puppeteer = require("puppeteer"); | |
const getData = (html) => { | |
const data = []; | |
const $ = cheerio.load(html); | |
// Select HTML elements to extract data from using Cheerio's jQuery like selectors |
This file contains 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, useEffect } from "react"; | |
export const useWindowSize = () => { | |
const isClient = typeof window === "object"; | |
const getSize = () => { | |
return { | |
width: isClient ? window.innerWidth : undefined, | |
height: isClient ? window.innerHeight : undefined, | |
}; |
This file contains 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, useEffect } from "react"; | |
export const useScrollPosition = () => { | |
const [scrollPosition, setScrollPosition] = useState(0); | |
const [scrollDirection, setScrollDirection] = useState(-1); | |
useEffect(() => { | |
const scrollYPos = window.pageYOffset || document.documentElement.scrollTop; | |
let lastScrollPos = scrollYPos; |
This file contains 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
// Remove arrows from number input | |
@mixin remove-arrows-number-input { | |
&::-webkit-outer-spin-button, | |
&::-webkit-inner-spin-button { | |
-webkit-appearance: none; | |
margin: 0; | |
} | |
&[type="number"] { |
This file contains 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 moment from "moment"; | |
export const convertDateTimeToCurrentTimezone = dateTime => { | |
const utcOffset = moment().utcOffset(); | |
return moment(dateTime).add(utcOffset, "minutes"); | |
}; | |
const createUTCDateTime = date => | |
moment(date) | |
.utc() |
This file contains 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
export const maskPrice = price => { | |
const scrubValue = price => { | |
const removedDecimal = value.replace(/\./g, ""); | |
const onlyDigits = new RegExp(/^(\d)+$/); | |
if (!onlyDigits.test(removedDecimal)) return; | |
const removedDecimalArray = removedDecimal.split(""); | |
removedDecimalArray.splice(-2, 0, "."); |
This file contains 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
function copyToClipboard(element) { | |
window.getSelection().removeAllRanges(); | |
const range = document.createRange(); | |
range.selectNode(element); | |
window.getSelection().addRange(range); | |
document.execCommand("copy"); | |
window.getSelection().removeAllRanges(); | |
} |
This file contains 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 React, { Component } from "react"; | |
function withDebounce(WrappedComponent) { | |
return class extends Component { | |
constructor(props) { | |
super(props); | |
this.timeout = null; | |
this.debounce = this.debounce.bind(this); | |
} |