@stryke/hooks 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,14 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useCopyToClipboard = useCopyToClipboard;
7
7
  var _base = require("@stryke/types/base");
8
8
  var _react = require("react");
9
- function i(r) {
9
+ function i(n) {
10
10
  const t = document.createElement("textarea");
11
- t.value = r, document.body.append(t), t.select(), document.execCommand("copy"), t.remove();
11
+ t.value = n, document.body.append(t), t.select(), document.execCommand("copy"), t.remove();
12
12
  }
13
13
  function useCopyToClipboard() {
14
- const [r, t] = (0, _react.useState)(null),
15
- n = (0, _react.useCallback)(e => {
16
- (async () => {
14
+ const [n, t] = (0, _react.useState)(null),
15
+ r = (0, _react.useCallback)(async e => {
16
+ await (async () => {
17
17
  try {
18
18
  if (navigator?.clipboard?.writeText) await navigator.clipboard.writeText(e ?? _base.EMPTY_STRING), t(e ?? _base.EMPTY_STRING);else throw new Error("writeText not supported");
19
19
  } catch {
@@ -21,5 +21,5 @@ function useCopyToClipboard() {
21
21
  }
22
22
  })();
23
23
  }, []);
24
- return [r, n];
24
+ return [n, r];
25
25
  }
@@ -3,4 +3,4 @@
3
3
  *
4
4
  * @returns A tuple with the copied value and a function to copy a value to the clipboard
5
5
  */
6
- export declare function useCopyToClipboard(): (string | ((value: string | null) => void) | null)[];
6
+ export declare function useCopyToClipboard(): (string | ((value: string | null) => Promise<void>) | null)[];
@@ -1 +1 @@
1
- import{EMPTY_STRING as o}from"@stryke/types/base";import{useCallback as a,useState as c}from"react";function i(r){const t=document.createElement("textarea");t.value=r,document.body.append(t),t.select(),document.execCommand("copy"),t.remove()}export function useCopyToClipboard(){const[r,t]=c(null),n=a(e=>{(async()=>{try{if(navigator?.clipboard?.writeText)await navigator.clipboard.writeText(e??o),t(e??o);else throw new Error("writeText not supported")}catch{i(e??o),t(e??o)}})()},[]);return[r,n]}
1
+ import{EMPTY_STRING as o}from"@stryke/types/base";import{useCallback as a,useState as c}from"react";function i(n){const t=document.createElement("textarea");t.value=n,document.body.append(t),t.select(),document.execCommand("copy"),t.remove()}export function useCopyToClipboard(){const[n,t]=c(null),r=a(async e=>{await(async()=>{try{if(navigator?.clipboard?.writeText)await navigator.clipboard.writeText(e??o),t(e??o);else throw new Error("writeText not supported")}catch{i(e??o),t(e??o)}})()},[]);return[n,r]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/hooks",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "type": "module",
5
5
  "description": "A package containing shared hooks that can be used in any React UI project",
6
6
  "repository": {
@@ -23,10 +23,10 @@
23
23
  "react": "^19.0.0",
24
24
  "react-dom": "^19.0.0",
25
25
  "react-native": "^0.77.0",
26
- "@stryke/env": ">=0.5.2",
27
- "@stryke/helpers": ">=0.4.3",
28
- "@stryke/type-checks": ">=0.1.2",
29
- "@stryke/types": ">=0.7.1"
26
+ "@stryke/env": ">=0.5.3",
27
+ "@stryke/helpers": ">=0.4.4",
28
+ "@stryke/type-checks": ">=0.1.3",
29
+ "@stryke/types": ">=0.7.2"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/react": "^19.0.8",