I am trying to understand a code written in TypeScript. I myself have a Java background and I find the syntax of the following code hard to understand. The code example is from the first Material UI Select code example:
const [labelWidth, setLabelWidth] = React.useState(0);
React.useEffect(() => {
setLabelWidth(inputLabel.current!.offsetWidth);
}, []);
So what exaclty is done here? What is the name of the variable const [labelWidt, setLabelWidth]
? Are these two variables or is this one variable? Like an array? Later in the code it labelWidth
has a number that can be used to set the width of some label. Then setLabelWidth
is used like a function that takes a param inputLabel.current!.offsetWidth
. Where is it defined that this is a function?
Can someone please explain?