Loading...
More JavaScript Posts
const ResponsiveCardImg = styled(Card.Img)`// For screens wider than 768px@media(min-width: 768px) {// Your responsive styles here.}// For screens smaller than 768px@media(max-width: 768px) {// Your responsive styles here.}`export default function App() {return (<MainContainer><Container><Card text='white' bg='dark' style={styles.mainCard}><ResponsiveCardImgstyle={styles.cardImage}onClick={handleClick}src={apeImage}alt='Degenerate Ape Academy'/><Card.Body><Card.Title className='text-center' as='h2'>{apeId}</Card.Title></Card.Body></Card></Container></MainContainer>);}
import React, { useState, useEffect } from 'react';import Link from 'next/link';export default function CookieBanner() {// Initialize with a default value (false if not previously set in localStorage)const [cookieConsent, setCookieConsent] = useState(() =>localStorage.getItem('cookieConsent') === 'true' ? true : false);useEffect(() => {const newCookieConsent = cookieConsent ? 'granted' : 'denied';window.gtag('consent', 'update', {analytics_storage: newCookieConsent});localStorage.setItem('cookieConsent', String(cookieConsent));}, [cookieConsent]);return !cookieConsent && (<div><div><p>We use cookies to enhance the user experience.{' '}<Link href='/privacy/'>View privacy policy</Link></p></div><div><button type="button" onClick={() => setCookieConsent(false)}>Decline</button><button type="button" onClick={() => setCookieConsent(true)}>Allow</button></div></div>)}
// Orconst randomColor = () => `#${(~~(Math.random()*(1<<24))).toString(16)}`;console.log(randomColor);
const copyToClipboard = str => {const el = document.createElement('textarea');el.value = str;el.setAttribute('readonly', '');el.style.position = 'absolute';el.style.left = '-9999px';document.body.appendChild(el);const selected =document.getSelection().rangeCount > 0? document.getSelection().getRangeAt(0): false;el.select();document.execCommand('copy');document.body.removeChild(el);if (selected) {document.getSelection().removeAllRanges();document.getSelection().addRange(selected);}};copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard.
const getSubsets = arr => arr.reduce((prev, curr) => prev.concat(prev.map(k => k.concat(curr))), [[]]);// ExamplesgetSubsets([1, 2]); // [[], [1], [2], [1, 2]]getSubsets([1, 2, 3]); // [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]
const toFixed = (n, fixed) => ~~(Math.pow(10, fixed) * n) / Math.pow(10, fixed);// ExamplestoFixed(25.198726354, 1); // 25.1toFixed(25.198726354, 2); // 25.19toFixed(25.198726354, 3); // 25.198toFixed(25.198726354, 4); // 25.1987toFixed(25.198726354, 5); // 25.19872toFixed(25.198726354, 6); // 25.198726