use-fit-text
use-fit-text copied to clipboard
Not resizing on dynamically received data
If the content of container is being changed dynamically then the hook does not recalculate the font size.
Looking back through the closed issues, I found this one, what says this was resolved back in v2.3.0 with the example given here example 4.
However, I am not convinced the solution solves the problem. While altering the text, the example does change the size of the font, but it does so using the previously rendered text, not the current text. This isn't obvious if you enter/delete using the provided text input, because the text is being resized to a similar number of characters. For example if your text is 20 characters long, adding another character will be it 21, and the font size calculation will happen on the original 20 which is close enough for it not to be a problem. So as you type the calculation is always done on the previous text, and so the problem appears to be resolved.
The problem becomes evident when the dynamic text is a different character length than the original. You can see the problem if you copy/paste characters into the input. See below