Skip to content

Commit 491888d

Browse files
committed
client(SelectInput.tsx): change the useEffect to useLayoutEffect
1 parent 985b434 commit 491888d

File tree

10 files changed

+9
-81
lines changed

10 files changed

+9
-81
lines changed

client/build/asset-manifest.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

client/build/favicon.ico

-3.78 KB
Binary file not shown.

client/build/index.html

Lines changed: 0 additions & 5 deletions
This file was deleted.

client/build/robots.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

client/build/static/css/main.ca9b3525.css

Lines changed: 0 additions & 4 deletions
This file was deleted.

client/build/static/css/main.ca9b3525.css.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

client/build/static/js/main.44218d5e.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

client/build/static/js/main.44218d5e.js.LICENSE.txt

Lines changed: 0 additions & 39 deletions
This file was deleted.

client/build/static/js/main.44218d5e.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

client/src/components/input/SelectInput.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, useEffect, useRef, useState } from "react";
1+
import { FC, useLayoutEffect, useRef, useState } from "react";
22
import { FiCheck } from "react-icons/fi";
33
import { IoMdClose } from "react-icons/io";
44
import { useDebounceValue } from "../../hooks/useDebounceValue";
@@ -23,8 +23,10 @@ const SelectInput: FC<SelectInputProps> = (props) => {
2323
const inputRef = useRef<HTMLInputElement>(null);
2424
const activeRef = useRef<HTMLSpanElement>(null);
2525

26-
useEffect(() => {
27-
if (debounceFilterValue.trim().length < 1) {
26+
useLayoutEffect(() => {
27+
const val = debounceFilterValue.toLowerCase().trim();
28+
29+
if (val.length < 1) {
2830
setOptions([...props.options]);
2931
activeRef.current?.scrollIntoView({
3032
block: "nearest",
@@ -33,11 +35,7 @@ const SelectInput: FC<SelectInputProps> = (props) => {
3335
return;
3436
}
3537

36-
setOptions(
37-
[...props.options].filter((o) =>
38-
o.includes(debounceFilterValue.toLowerCase().trim())
39-
)
40-
);
38+
setOptions([...props.options].filter((o) => o.includes(val)));
4139
}, [debounceFilterValue, props.options]);
4240

4341
const selectValue = (value: string): void => {
@@ -126,10 +124,9 @@ const SelectInput: FC<SelectInputProps> = (props) => {
126124
<li
127125
key={option}
128126
onClick={() => selectValue(option)}
129-
className={`flex items-center gap-4 py-1 px-2 transition-all duration-150
130-
hover:bg-gh-button cursor-pointer text-gh-text min-w-[10rem] ${
131-
i === 0 ? "" : "border-t border-solid border-gh-border-dark"
132-
}`}
127+
className="flex items-center gap-4 py-1 px-2 transition-all duration-150
128+
hover:bg-gh-button cursor-pointer text-gh-text min-w-[10rem] border-t
129+
border-solid border-gh-border-dark"
133130
>
134131
{isSelected && (
135132
<span ref={activeRef}>

0 commit comments

Comments
 (0)