From 172d81da306f1c59c359d9718e8a5f426e6cdf38 Mon Sep 17 00:00:00 2001 From: Mayank Kumar Chaudhari Date: Fri, 19 Apr 2024 17:51:52 +0530 Subject: [PATCH] Deepsourcce: Fix performance issues --- lib/r18gs/tests/use-rgs.test.tsx | 16 ++++++++-------- packages/shared-ui/src/root/counter.tsx | 15 ++++++++------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/r18gs/tests/use-rgs.test.tsx b/lib/r18gs/tests/use-rgs.test.tsx index b1c8fda6..afd0de1c 100644 --- a/lib/r18gs/tests/use-rgs.test.tsx +++ b/lib/r18gs/tests/use-rgs.test.tsx @@ -1,19 +1,19 @@ import { describe, test } from "vitest"; import { act, fireEvent, render, screen } from "@testing-library/react"; import useRGS from "../src"; +import { ChangeEvent, useCallback } from "react"; function Component1() { const [count, setCount] = useRGS("count", 0); + const handleChange = useCallback( + (e: ChangeEvent) => { + setCount(parseInt(e.target.value)); + }, + [setCount], + ); return (
- { - setCount(parseInt(e.target.value)); - }} - type="number" - value={count} - /> +
); } diff --git a/packages/shared-ui/src/root/counter.tsx b/packages/shared-ui/src/root/counter.tsx index 8c4da3c4..44398ec8 100644 --- a/packages/shared-ui/src/root/counter.tsx +++ b/packages/shared-ui/src/root/counter.tsx @@ -2,19 +2,20 @@ import useRGS from "r18gs"; import { COUNTER } from "../constants/global-states"; +import { ChangeEvent, useCallback } from "react"; export default function Counter() { const [count, setCount] = useRGS(COUNTER, 0); + const handleChange = useCallback( + (e: ChangeEvent) => { + setCount(parseInt(e.target.value)); + }, + [setCount], + ); return (

Clinet component 1

- { - setCount(parseInt(e.target.value.trim())); - }} - type="number" - value={count} - /> +
); }