Fix Next problem with copy

Next complains when the server renders something different then the client, therfor we move the differing logic to `useEffect`
This commit is contained in:
Marcus Blättermann 2022-11-17 16:10:34 +01:00
parent 4c7552dcb1
commit c3e1c771ac
No known key found for this signature in database
GPG Key ID: A1E1F04008AC450D

View File

@ -1,4 +1,4 @@
import React, { useState, useRef } from 'react'
import React, { useState, useRef, useEffect } from 'react'
import Icon from './icon'
import classes from '../styles/copy.module.sass'
@ -16,7 +16,11 @@ export function copyToClipboard(ref, callback) {
export default function CopyInput({ text, prefix }) {
const isClient = typeof window !== 'undefined'
const supportsCopy = isClient && document.queryCommandSupported('copy')
const [supportsCopy, setSupportsCopy] = useState(false)
useEffect(() => {
setSupportsCopy(isClient && document.queryCommandSupported('copy'))
}, [])
const textareaRef = useRef()
const [copySuccess, setCopySuccess] = useState(false)
const onClick = () => copyToClipboard(textareaRef, setCopySuccess)