• Nov 19, 2022 •CodeCatch
0 likes • 1 view
// `date` is a `Date` object const formatYmd = date => date.toISOString().slice(0, 10); // Example formatYmd(new Date()); // 2020-05-06
• Jan 25, 2023 •C S
1 like • 17 views
export const Main = () => { const [title, setTitle] = useState(''); return ( <ChildComponent title={title} onChange={e => setTitle(e.target.value)} /> ); }; export const ChildComponent = ({ title, onChange }) => { return ( <Box component="form" onSubmit={() => {}} noValidate mt={5}> <TextField fullWidth id="title" label="Title" name="title" autoComplete="title" autoFocus color="primary" variant="filled" InputLabelProps={{ shrink: true }} value={title} onChange={onChange} /> </Box> ); };
• Oct 9, 2023 •Helper
0 likes • 279 views
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> ) }
• Mar 9, 2021 •LeifMessinger
alert("bruh")
• Nov 8, 2023 •LeifMessinger
0 likes • 6 views
function copyString(text){ async function navigatorClipboardCopy(text){ if(document.location.protocol != "https:"){ return false; } return new Promise((resolve, reject)=>{ navigator.clipboard.writeText(text).then(()=>{resolve(true);}, ()=>{resolve(false);}); }); } function domCopy(text){ if(!(document.execCommand)){ console.warn("They finally deprecated document.execCommand!"); } const input = document.createElement('textarea'); input.value = text; document.body.appendChild(input); input.select(); const success = document.execCommand('copy'); document.body.removeChild(input); return success; } function promptCopy(){ prompt("Copy failed. Might have ... somewhere. Check console.", text); console.log(text); } function done(){ alert("Copied to clipboard"); } navigatorClipboardCopy(text).catch(()=>{return false;}).then((success)=>{ if(success){ done(); }else{ if(domCopy(text)){ done(); }else{ promptCopy(); } } }); }
0 likes • 0 views
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.