I have been using react hooks more but one thing that I have found to be a pain is needing to pass a lot of variables into my utility functions because I don't have access to them anymore. For example say I have a component like this:
export const ListItem(props) {
const {id, item, itemStatuses, workflows, taks} = props
const [checked, setChecked] = useState(false)
return (
<CheckboxItem
key={id}
title={item.title}
onPress={() => handleCheckboxPress(id, item, itemStatuses,
setChecked, workflows)}
/>
)
}
And the handleCheckboxPress is a function outside of the component that runs a bunch of logic and needs all (or most of) the props from the component to figure out some state, and then also needed to setState callback as well to be able to change some internal state.
In the past I would just make them methods of the class and I would have access to all props and setStates, etc.
Is there some pattern to avoid having to pass all of these props into a bunch of utility functions?
I have read that putting all of this logic in functions INSIDE the component is bad for performance because react recreates all of those functions on every render. Is this true or is that a valid pattern because that would solve my pain point.