Wrap an Element - Click and It's Copied -
Gives you access to context similar to useFormikContext
yarn add wrappedcopy
You must Wrap you app with the Context Provider, Provided.
Ps. You can also just Wrap your View
import React, { Component } from 'react'
import { WrappedCopyContextProvider } from 'wrappedcopy'
class Example extends Component {
render() {
return (
<WrappedCopyContextProvider>
<App />
</WrappedCopyContextProvider>
)
}
}
Then in your View -
import React, { Component } from 'react'
import { WrappedElement, useCopiedContext } from 'wrappedcopy'
const MyComponent = () => {
const { copiedText } = useCopiedContext()
return (
<div>
<WrappedElement>Hello</WrappedElement>
</div>
)
}
Wrap the element you want to be Copied to your clipboard with <WrappedElement>
Should You need to read the value copied you can destruct it from the Copied Context using
const {copiedText} = useCopiedContext()
I have not tested on Classes but will soon as I need Legacy support for this
As such for failsafe I export the raw
Context as-well
import {CopyContext} from 'wrappedcopy'
yarn start # runs rollup with watch flag
cd example
yarn
yar start # runs create-react-app dev server
Made with create-react-library
yarn publish
yarn run deploy
MIT © ahwelgemoed