My question is more oriented on the performance side I believe. In the following case I am rendering a select component.
Is there a problem (or a performance problem) in redeclaring the onValueChange function each time the select rerenders itself? Because in some other scenario we will have to go back to classes which will declare the onValueChange function only once.
Putting this function in the same file in this particular case would mean to send almost all the parameters received and the rest of the consts.
export default function CustomSelect({data, keyFn, displayFn, onChange}) {
const [selectedObj, setSelectedObj] = useState({})
const [selectedObjId, setSelectedObjId] = useState('')
const onValueChange = event => {
//use of data, keyFn, displayFn, onChange
onChange && onChange(selectedObj)
}
return (
<select onChange={onValueChange} ...>
...
</select>
)
}