File tree Expand file tree Collapse file tree
packages/js/ui/src/wp/button-group-control Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { Button , __experimentalGrid as Grid } from '@wordpress/components' ;
2+ import { useCallback } from 'react' ;
23import { FieldsetAsLabel } from '../fieldset-as-label/index.js' ;
34
45type Option = {
@@ -19,15 +20,18 @@ export interface ButtonGroupControlProps {
1920export function ButtonGroupControl ( {
2021 label,
2122 options,
22- value,
23+ value = [ ] ,
2324 onChange,
2425} : ButtonGroupControlProps ) {
25- const toggleValue = ( val : string ) => {
26- const newValue = value . includes ( val )
27- ? value . filter ( ( v ) => v !== val )
28- : [ ...value , val ] ;
29- onChange ( newValue ) ;
30- } ;
26+ const toggleValue = useCallback (
27+ ( val : string ) => {
28+ const newValue = value . includes ( val )
29+ ? value . filter ( ( v ) => v !== val )
30+ : [ ...value , val ] ;
31+ onChange ( newValue ) ;
32+ } ,
33+ [ value , onChange ] ,
34+ ) ;
3135
3236 return (
3337 < FieldsetAsLabel label = { label } >
You can’t perform that action at this time.
0 commit comments