I am trying to build a component with some validations depending on user's clipboard.
import { useState } from 'react'
export default function useCopiedFromClipboard() {
const [copiedData, setCopiedData] = useState<string>('')
navigator.clipboard
.readText()
.then((text) => {
setCopiedData(text)
})
.catch((err) => {
console.error('Failed to read clipboard contents: ', err)
})
return { copiedData }
}
So what I really want to do is use this hook inside a component.
import React from 'react'
export default function MyComponent() {
const {copiedData} = useCopiedFromClipboard()
useEffect(()=>{
console.log('Run')
},[copiedData])
return (
<></>
)
}
I am expecting this useEffect to run everytime the user copies something to their clipboard. But this is not working.
Does anyone have any idea of how to implement this one ?
Hope this helps you