next-recomponents 1.3.0 → 1.3.2

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.
package/dist/index.js CHANGED
@@ -3026,25 +3026,23 @@ function Button(_a) {
3026
3026
  "disabled"
3027
3027
  ]);
3028
3028
  const [isLoading, setIsloading] = (0, import_react.useState)(false);
3029
- const [newProps, setNewProps] = (0, import_react.useState)(__spreadValues({}, props));
3030
- (0, import_react.useEffect)(() => {
3031
- const oldProps = __spreadValues({}, props);
3032
- const np = __spreadValues({}, props);
3033
- for (let prop in props) {
3034
- if (prop.startsWith("on")) {
3035
- np[prop] = (e) => __async(null, null, function* () {
3036
- setIsloading(true);
3037
- console.log(oldProps[prop]);
3038
- yield oldProps[prop](e);
3039
- setIsloading(false);
3040
- });
3041
- }
3042
- }
3043
- setNewProps(np);
3044
- }, [props]);
3045
3029
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
3046
3030
  "button",
3047
- __spreadProps(__spreadValues({}, newProps), {
3031
+ __spreadProps(__spreadValues({}, Object.assign(
3032
+ {},
3033
+ ...Object.keys(props).map((prop) => {
3034
+ const originalHandler = props[prop];
3035
+ const newProp = { [prop]: originalHandler };
3036
+ if (prop.startsWith("on") && typeof originalHandler === "function") {
3037
+ newProp[prop] = (e) => __async(null, null, function* () {
3038
+ setIsloading(true);
3039
+ originalHandler && (yield originalHandler(e));
3040
+ setIsloading(false);
3041
+ });
3042
+ }
3043
+ return newProp;
3044
+ })
3045
+ )), {
3048
3046
  className: [
3049
3047
  className,
3050
3048
  "p-2 border shadow rounded flex gap-1 justify-center items-center",
package/dist/index.mjs CHANGED
@@ -2991,7 +2991,6 @@ function Alert(_a) {
2991
2991
 
2992
2992
  // src/button/index.tsx
2993
2993
  import {
2994
- useEffect,
2995
2994
  useState
2996
2995
  } from "react";
2997
2996
  import { jsxs } from "react/jsx-runtime";
@@ -3012,25 +3011,23 @@ function Button(_a) {
3012
3011
  "disabled"
3013
3012
  ]);
3014
3013
  const [isLoading, setIsloading] = useState(false);
3015
- const [newProps, setNewProps] = useState(__spreadValues({}, props));
3016
- useEffect(() => {
3017
- const oldProps = __spreadValues({}, props);
3018
- const np = __spreadValues({}, props);
3019
- for (let prop in props) {
3020
- if (prop.startsWith("on")) {
3021
- np[prop] = (e) => __async(null, null, function* () {
3022
- setIsloading(true);
3023
- console.log(oldProps[prop]);
3024
- yield oldProps[prop](e);
3025
- setIsloading(false);
3026
- });
3027
- }
3028
- }
3029
- setNewProps(np);
3030
- }, [props]);
3031
3014
  return /* @__PURE__ */ jsxs(
3032
3015
  "button",
3033
- __spreadProps(__spreadValues({}, newProps), {
3016
+ __spreadProps(__spreadValues({}, Object.assign(
3017
+ {},
3018
+ ...Object.keys(props).map((prop) => {
3019
+ const originalHandler = props[prop];
3020
+ const newProp = { [prop]: originalHandler };
3021
+ if (prop.startsWith("on") && typeof originalHandler === "function") {
3022
+ newProp[prop] = (e) => __async(null, null, function* () {
3023
+ setIsloading(true);
3024
+ originalHandler && (yield originalHandler(e));
3025
+ setIsloading(false);
3026
+ });
3027
+ }
3028
+ return newProp;
3029
+ })
3030
+ )), {
3034
3031
  className: [
3035
3032
  className,
3036
3033
  "p-2 border shadow rounded flex gap-1 justify-center items-center",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recomponents",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -32,25 +32,26 @@ export default function Button({
32
32
  ...props
33
33
  }: Props) {
34
34
  const [isLoading, setIsloading] = useState(false);
35
- const [newProps, setNewProps] = useState({ ...props });
36
- useEffect(() => {
37
- const oldProps: any = { ...props };
38
- const np: any = { ...props };
39
- for (let prop in props) {
40
- if (prop.startsWith("on")) {
41
- np[prop] = async (e: React.FormEvent<HTMLButtonElement>) => {
42
- setIsloading(true);
43
- console.log(oldProps[prop]);
44
- await oldProps[prop](e);
45
- setIsloading(false);
46
- };
47
- }
48
- }
49
- setNewProps(np);
50
- }, [props]);
35
+
51
36
  return (
52
37
  <button
53
- {...newProps}
38
+ {...Object.assign(
39
+ {},
40
+ ...Object.keys(props).map((prop) => {
41
+ const originalHandler = (props as any)[prop];
42
+ const newProp: any = { [prop]: originalHandler };
43
+
44
+ if (prop.startsWith("on") && typeof originalHandler === "function") {
45
+ newProp[prop] = async (e: any) => {
46
+ setIsloading(true);
47
+ originalHandler && (await originalHandler(e));
48
+ setIsloading(false);
49
+ };
50
+ }
51
+
52
+ return newProp;
53
+ })
54
+ )}
54
55
  className={[
55
56
  className,
56
57
  "p-2 border shadow rounded flex gap-1 justify-center items-center",