I am trying to use an array state for a React functional component.
This is the code I tried.
const inputLabel = Array(5).fill(React.useRef(null));
const [labelWidth, setLabelWidth] = React.useState(0);
React.useEffect(() => {
inputLabel.map((label, i) => {
setLabelWidth({...labelWidth, [i]: label.current.offsetWidth});
});
}, []);
This is what I tried, but showing an error of
React Hook React.useEffect has missing dependencies: 'inputLabel' and 'labelWidth'
Looking for React experts' help. Thanks!