Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not resizing on dynamically received data #2

Closed
seleckis opened this issue Dec 19, 2019 · 8 comments
Closed

Not resizing on dynamically received data #2

seleckis opened this issue Dec 19, 2019 · 8 comments

Comments

@seleckis
Copy link

If the content of container is being changed dynamically then the hook does not recalculate the font size

saltycrane added a commit that referenced this issue Dec 31, 2019
@saltycrane
Copy link
Owner

saltycrane commented Dec 31, 2019

@seleckis I published use-fit-text@2.1.0 which uses ResizeObserver. See if that works for you.

@kriziacamilleuayan
Copy link

please update readme so that we'll know how to use that :)

@Nantris
Copy link

Nantris commented Jan 27, 2020

@saltycrane, this only seems to work if the element is not of a fixed size, am I wrong?

The issue we're seeing is that when text is added or removed programmatically, the text doesn't resize. Is there a way to work around this at present?

Thank you for sharing your great work!

@saltycrane
Copy link
Owner

Ah sorry guys, I didn't read the original issue carefully. The change I made in v2 was to support recalculating upon a resize of the container, but it doesn't recalculate if the content text changes. Currently the way I handle this is by using the React key attribute to cause a remount of the component to cause useFitText to recalculate. Here is more info about that: https://www.saltycrane.com/blog/2019/12/how-remount-react-component-when-prop-changes/

@Nantris
Copy link

Nantris commented Jan 28, 2020

Beautiful! Thank you @saltycrane!

@saltycrane
Copy link
Owner

Update: I just published use-fit-text@2.3.0 which now recalculates the font size when the content text changes. See the example here.

@Nantris
Copy link

Nantris commented Jun 16, 2020

@saltycrane is there any benefit to using the new version compared with the key-based workaround? Does it just implement the same behind the scenes?

@saltycrane
Copy link
Owner

hi @slapbox, I'd say the main benefit is that it should work automatically without needing to add the React key. There actually is a difference in the implementation-- I'm using innerHTML from the div's ref to check if the contents changed. You can see the code here: https://github.com/saltycrane/use-fit-text/blob/v2.3.0/index.ts#L83-L97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants