Not sure if this is a bug or a niggle, or simply how it's "supposed" to work, but...
Let's say I have a state like this :
state = {
stuff: '',
}
And I update the state from a text input like this :
onChange = e => {
this.setState({
stuff: e.target.value
});
console.log(this.state.stuff.length);
}
The console log doesn't output the correct length when the text input is changed.
For example, if the text input contained the word 'things', the console log correctly reports that the length of stuff
is 4
(As 0 is also counted as a number).
Now, if the client deletes one character, making stuff
now contain 'thing' the console will report that the length of stuff
is now 5
and not 3
as expected.
It's like it's counting the delete keypress as a new character, which in turn throws off the count completely as it will never return the correct result after this. Deleting all chars one at a time results in a final count of 1
when it should in fact be empty (as 0 is a valid number).
Not very helpful when you're trying to determine if a certain state contains a minimum amount of chars OR is empty - which in this scenario it never would be. I know there are other ways to check the data but I've just discovered this and thought it was worth mentioning.