If I have a hook, e.g:
const useGetSet = (label: string) => {
const [get, set] = useState(label);
return { get, set };
};
I can map it over an array, e.g:
const labels = ['one', 'two'].map(useGetSet);
But if I expand this to a lambda, e.g:
const labels = ['one', 'two'].map((l) => useGetSet(l))
Then it causes:
React Hook
"useGetSet"cannot be called inside a callback.
React Hooks must be called in a React function component or a custom React Hook function. (react-hooks/rules-of-hooks) eslint
Why this difference, shouldn't they be equivalent?
Additionally, if this is a violation of the rule of hooks, how should this be done?