Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 90b7e99

Browse files
matijsImreBognarUltimaker
authored andcommitted
Generate a uuid only once
Instead of generating a new uuid on every render, generate it only once for the lifecycle of the component.
1 parent 5722149 commit 90b7e99

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/components/search_bar/search_bar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class SearchBar extends React.Component<SearchBarProps, SearchBarState> {
2121
query: '',
2222
}
2323

24+
id = uuidv4();
25+
2426
debouncedEmit = (({ onChange, emitDelay }) => debounce(
2527
onChange, emitDelay,
2628
))(this.props);
@@ -66,9 +68,8 @@ class SearchBar extends React.Component<SearchBarProps, SearchBarState> {
6668

6769
render() {
6870
const { query } = this.state;
69-
const { onChange } = this;
71+
const { id, onChange } = this;
7072
const { placeholder } = this.props;
71-
const id = uuidv4();
7273
return (
7374
<div className="search-bar">
7475
<span className="search-bar__icon">

0 commit comments

Comments
 (0)