Skip to content

Commit

Permalink
Type errors only in development
Browse files Browse the repository at this point in the history
  • Loading branch information
wardoost committed Apr 8, 2019
1 parent 90d0a5d commit 8b04ef0
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/useCopyToClipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,22 @@ const useCopyToClipboard = (): [CopyToClipboardState, (value: string) => void] =

const copyToClipboard = useCallback((value) => {
try {
if (!value) {
throw new Error('No value to copy to clipboard')
}

if (typeof value !== "string") {
throw new Error(`Cannot copy typeof ${typeof value} to clipboard, must be a string`);
if (process.env.NODE_ENV === 'development') {
if (typeof value !== "string") {
console.error(`Cannot copy typeof ${typeof value} to clipboard, must be a string`);
}
}

const noUserInteraction = writeText(value);
if (!mounted.current) return;

if (!mounted.current) return;
setState({
value,
error: undefined,
noUserInteraction
});
} catch (error) {
if (!mounted.current) return;

setState({
value: undefined,
error,
Expand Down

0 comments on commit 8b04ef0

Please sign in to comment.