@@ -40,13 +40,16 @@ Use to help merchants complete text input quickly from a list of options.
4040
4141``` jsx
4242function AutocompleteExample () {
43- const deselectedOptions = [
44- {value: ' rustic' , label: ' Rustic' },
45- {value: ' antique' , label: ' Antique' },
46- {value: ' vinyl' , label: ' Vinyl' },
47- {value: ' vintage' , label: ' Vintage' },
48- {value: ' refurbished' , label: ' Refurbished' },
49- ];
43+ const deselectedOptions = useMemo (
44+ () => [
45+ {value: ' rustic' , label: ' Rustic' },
46+ {value: ' antique' , label: ' Antique' },
47+ {value: ' vinyl' , label: ' Vinyl' },
48+ {value: ' vintage' , label: ' Vintage' },
49+ {value: ' refurbished' , label: ' Refurbished' },
50+ ],
51+ [],
52+ );
5053 const [selectedOptions , setSelectedOptions ] = useState ([]);
5154 const [inputValue , setInputValue ] = useState (' ' );
5255 const [options , setOptions ] = useState (deselectedOptions);
@@ -113,13 +116,16 @@ Use to help merchants select multiple options from a list curated by the text in
113116
114117``` jsx
115118function MultiAutocompleteExample () {
116- const deselectedOptions = [
117- {value: ' rustic' , label: ' Rustic' },
118- {value: ' antique' , label: ' Antique' },
119- {value: ' vinyl' , label: ' Vinyl' },
120- {value: ' vintage' , label: ' Vintage' },
121- {value: ' refurbished' , label: ' Refurbished' },
122- ];
119+ const deselectedOptions = useMemo (
120+ () => [
121+ {value: ' rustic' , label: ' Rustic' },
122+ {value: ' antique' , label: ' Antique' },
123+ {value: ' vinyl' , label: ' Vinyl' },
124+ {value: ' vintage' , label: ' Vintage' },
125+ {value: ' refurbished' , label: ' Refurbished' },
126+ ],
127+ [],
128+ );
123129 const [selectedOptions , setSelectedOptions ] = useState ([' rustic' ]);
124130 const [inputValue , setInputValue ] = useState (' ' );
125131 const [options , setOptions ] = useState (deselectedOptions);
@@ -146,10 +152,13 @@ function MultiAutocompleteExample() {
146152 [deselectedOptions],
147153 );
148154
149- const handleSelect = useCallback ((selected ) => {
150- setSelectedOptions (selected);
151- updateText (' ' );
152- }, []);
155+ const handleSelect = useCallback (
156+ (selected ) => {
157+ setSelectedOptions (selected);
158+ updateText (' ' );
159+ },
160+ [updateText],
161+ );
153162
154163 const removeTag = useCallback (
155164 (tag ) => (event ) => {
@@ -320,13 +329,16 @@ Use to indicate loading state to merchants while option data is processing.
320329
321330``` jsx
322331function AutocompleteExample () {
323- const deselectedOptions = [
324- {value: ' rustic' , label: ' Rustic' },
325- {value: ' antique' , label: ' Antique' },
326- {value: ' vinyl' , label: ' Vinyl' },
327- {value: ' vintage' , label: ' Vintage' },
328- {value: ' refurbished' , label: ' Refurbished' },
329- ];
332+ const deselectedOptions = useMemo (
333+ () => [
334+ {value: ' rustic' , label: ' Rustic' },
335+ {value: ' antique' , label: ' Antique' },
336+ {value: ' vinyl' , label: ' Vinyl' },
337+ {value: ' vintage' , label: ' Vintage' },
338+ {value: ' refurbished' , label: ' Refurbished' },
339+ ],
340+ [],
341+ );
330342 const [selectedOptions , setSelectedOptions ] = useState ([]);
331343 const [inputValue , setInputValue ] = useState (' ' );
332344 const [options , setOptions ] = useState (deselectedOptions);
@@ -354,7 +366,7 @@ function AutocompleteExample() {
354366 setLoading (false );
355367 }, 300 );
356368 },
357- [deselectedOptions, options, loading],
369+ [deselectedOptions, loading],
358370 );
359371
360372 const updateSelection = useCallback (
@@ -464,7 +476,7 @@ function AutoCompleteLazyLoadExample() {
464476 setOptions (resultOptions);
465477 setInputValue;
466478 },
467- [deselectedOptions, options ],
479+ [deselectedOptions],
468480 );
469481
470482 const textField = (
@@ -530,13 +542,16 @@ Use to indicate there are no search results.
530542
531543``` jsx
532544function AutocompleteExample () {
533- const deselectedOptions = [
534- {value: ' rustic' , label: ' Rustic' },
535- {value: ' antique' , label: ' Antique' },
536- {value: ' vinyl' , label: ' Vinyl' },
537- {value: ' vintage' , label: ' Vintage' },
538- {value: ' refurbished' , label: ' Refurbished' },
539- ];
545+ const deselectedOptions = useMemo (
546+ () => [
547+ {value: ' rustic' , label: ' Rustic' },
548+ {value: ' antique' , label: ' Antique' },
549+ {value: ' vinyl' , label: ' Vinyl' },
550+ {value: ' vintage' , label: ' Vintage' },
551+ {value: ' refurbished' , label: ' Refurbished' },
552+ ],
553+ [],
554+ );
540555 const [selectedOptions , setSelectedOptions ] = useState ([]);
541556 const [inputValue , setInputValue ] = useState (' ' );
542557 const [options , setOptions ] = useState (deselectedOptions);
@@ -564,7 +579,7 @@ function AutocompleteExample() {
564579 setLoading (false );
565580 }, 300 );
566581 },
567- [deselectedOptions, loading, options ],
582+ [deselectedOptions, loading],
568583 );
569584
570585 const updateSelection = useCallback (
@@ -621,13 +636,16 @@ Use to help merchants complete an action quickly.
621636
622637``` jsx
623638function AutocompleteActionBeforeExample () {
624- const deselectedOptions = [
625- {value: ' rustic' , label: ' Rustic' },
626- {value: ' antique' , label: ' Antique' },
627- {value: ' vinyl' , label: ' Vinyl' },
628- {value: ' vintage' , label: ' Vintage' },
629- {value: ' refurbished' , label: ' Refurbished' },
630- ];
639+ const deselectedOptions = useMemo (
640+ () => [
641+ {value: ' rustic' , label: ' Rustic' },
642+ {value: ' antique' , label: ' Antique' },
643+ {value: ' vinyl' , label: ' Vinyl' },
644+ {value: ' vintage' , label: ' Vintage' },
645+ {value: ' refurbished' , label: ' Refurbished' },
646+ ],
647+ [],
648+ );
631649 const [selectedOptions , setSelectedOptions ] = useState ([]);
632650 const [inputValue , setInputValue ] = useState (' ' );
633651 const [options , setOptions ] = useState (deselectedOptions);
@@ -714,13 +732,16 @@ Use to help merchants complete an action quickly with wrapping lines of text.
714732
715733``` jsx
716734function AutocompleteActionBeforeExample () {
717- const deselectedOptions = [
718- {value: ' rustic' , label: ' Rustic' },
719- {value: ' antique' , label: ' Antique' },
720- {value: ' vinyl' , label: ' Vinyl' },
721- {value: ' vintage' , label: ' Vintage' },
722- {value: ' refurbished' , label: ' Refurbished' },
723- ];
735+ const deselectedOptions = useMemo (
736+ () => [
737+ {value: ' rustic' , label: ' Rustic' },
738+ {value: ' antique' , label: ' Antique' },
739+ {value: ' vinyl' , label: ' Vinyl' },
740+ {value: ' vintage' , label: ' Vintage' },
741+ {value: ' refurbished' , label: ' Refurbished' },
742+ ],
743+ [],
744+ );
724745 const [selectedOptions , setSelectedOptions ] = useState ([]);
725746 const [inputValue , setInputValue ] = useState (' ' );
726747 const [options , setOptions ] = useState (deselectedOptions);
@@ -809,13 +830,16 @@ Use to help merchants complete a destructive action quickly.
809830
810831``` jsx
811832function AutocompleteActionBeforeExample () {
812- const deselectedOptions = [
813- {value: ' rustic' , label: ' Rustic' },
814- {value: ' antique' , label: ' Antique' },
815- {value: ' vinyl' , label: ' Vinyl' },
816- {value: ' vintage' , label: ' Vintage' },
817- {value: ' refurbished' , label: ' Refurbished' },
818- ];
833+ const deselectedOptions = useMemo (
834+ () => [
835+ {value: ' rustic' , label: ' Rustic' },
836+ {value: ' antique' , label: ' Antique' },
837+ {value: ' vinyl' , label: ' Vinyl' },
838+ {value: ' vintage' , label: ' Vintage' },
839+ {value: ' refurbished' , label: ' Refurbished' },
840+ ],
841+ [],
842+ );
819843 const [selectedOptions , setSelectedOptions ] = useState ([]);
820844 const [inputValue , setInputValue ] = useState (' ' );
821845 const [options , setOptions ] = useState (deselectedOptions);
0 commit comments