I am looking at an example in the documentation of fluentui:
...
export const TextFieldControlledExample: React.FunctionComponent = () => {
const [firstTextFieldValue, setFirstTextFieldValue] = React.useState('');
...
const onChangeFirstTextFieldValue = React.useCallback(
(event: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, newValue?: string) => {
setFirstTextFieldValue(newValue || '');
},
[],
);
...
return (
...
<TextField
label="Basic controlled TextField"
value={firstTextFieldValue}
onChange={onChangeFirstTextFieldValue}
styles={textFieldStyles}
/>
...
);
};
Why are they using React.useCallBack here instead of a normal function? E.g. what is there to memoize?