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
| //nextjs server | |
| import { NextResponse } from 'next/server'; | |
| import pets from '../pets.json'; | |
| export async function GET(request) { | |
| const { searchParams } = new URL(request.url); | |
| const query = searchParams.get('query'); | |
| const filteredPets = pets.filter((pet) => { | |
| return pet.name.toLowerCase().includes(query.toLowerCase()); | |
| }); |
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"; | |
| function useToggle(initialState){ | |
| const [state, setState] = useState(initialState || false); | |
| return [state, () => setState(!state)]; | |
| }; | |
| //Use it | |
| // const [on, toggle] = useToggle(); |
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
| const LazyLoadImage = ({ | |
| alt, | |
| src, | |
| className, | |
| loadInitially = false, | |
| observerOptions = { root: null, rootMargin: '200px 0px' }, | |
| ...props | |
| }) => { | |
| const observerRef = React.useRef(null); | |
| const imgRef = React.useRef(null); |
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, useEffect, useRef } from "react"; | |
| function App() { | |
| // Create a ref that we add to the element for which we want to detect outside clicks | |
| const ref = useRef(); | |
| // State for our modal | |
| const [isModalOpen, setModalOpen] = useState(false); | |
| // Call hook passing in the ref and a function to call on outside click | |
| useOnClickOutside(ref, () => setModalOpen(false)); | |
| return ( |
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
| const useWindowSize = () => { | |
| const [windowSize, setWindowSize] = useState({ | |
| width: undefined, | |
| height: undefined | |
| }); | |
| useEffect(() => { | |
| function handleResize() { | |
| setWindowSize({ | |
| width: window.innerWidth, |
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
| const zoom = document.querySelector('.zoomIn'); | |
| const minZoom = 1; | |
| const maxZoom = 2; | |
| addEventListener('scroll', e => { | |
| const vh = window.innerHeight / 100; | |
| const scrollTop = document.documentElement.scrollTop; | |
| const start = 100 * vh; | |
| const stop = 200 * vh; | |
| if (scrollTop > start && scrollTop < stop) { |
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
| function onScroll(container) { | |
| const div = container.querySelector(".selector"); | |
| const rect = div.getBoundingClientRect(); | |
| const top = Math.max(rect.top, 0); | |
| const wl = | |
| Array.from(div.querySelectorAll(".selector")).reduce((a, b) => { | |
| return a + b.clientWidth + 40; | |
| }, 0) + 120; // allow for extra padding; | |
| const hl = rect.height; | |
| const ww = window.innerWidth; |
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
| const puppeteer = require("puppeteer"); | |
| const SCRAPE_URL = `https://coincodex.com/`; | |
| (async () => { | |
| const browser = await puppeteer.launch({ headless: false }); | |
| const page = await browser.newPage(); | |
| await page.goto(SCRAPE_URL); | |
| await page.screenshot({ path: "sample.png" }); | |
| const coining = await page.evaluate(() => |
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 React from "react" | |
| import { Link, graphql } from "gatsby" | |
| import Layout from "../components/layout" | |
| import SEO from "../components/seo" | |
| const SitePosts = ({ data }) => { | |
| const ourPosts = data.allContentfulSitePost.edges | |
| // console.log(ourPosts); | |
| return ( |
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 React from "react" | |
| import { Link, graphql } from "gatsby" | |
| import Layout from "../components/layout" | |
| import SEO from "../components/seo" | |
| const SitePosts = ({ data }) => { | |
| const { heading, subheading, description, image } = data.contentfulSitePost | |
| return ( | |
| <Layout> | |
| <SEO title={heading} /> |
NewerOlder