Giter Club home page Giter Club logo

Comments (3)

masonlee avatar masonlee commented on June 15, 2024

I am starting with the text transparent and then using the useFitText({onFinish}) callback to make it opaque after resizing completes. It's a bit of a pain to do this everywhere manually, but it works.

from use-fit-text.

bmovement avatar bmovement commented on June 15, 2024

I am starting with the text transparent and then using the useFitText({onFinish}) callback to make it opaque after resizing completes. It's a bit of a pain to do this everywhere manually, but it works.

Thanks for the idea @masonlee... I'm using this custom hook:

export const useFitTextFinished = (options) => {
  const [finished, setFinished] = useState(false);
  const { ref, fontSize } = useFitText({
    ...options,
    onFinish: () => setFinished(true),
  });
  return { ref, fontSize, finished };
};

Edit:

Ok, now I'm getting wacky with it... considering this method so I don't have to explicitly handle hiding outside of the hook:

export const useFitTextFinished = ({ color: finishedColor, ...options }) => {
  const [color, setColor] = useState("transparent");
  const { ref, fontSize } = useFitText({
    ...options,
    onFinish: () => setColor(finishedColor),
  });
  return { ref, fontSize, color };
};

from use-fit-text.

choyongjoon avatar choyongjoon commented on June 15, 2024

I made this custom hook. It uses undefined color to use the original color.

import { useState } from 'react';
import useFitText, { TOptions } from 'use-fit-text';

const useBetterFitText = (options?: TOptions) => {
  const [color, setColor] = useState<'transparent' | undefined>('transparent');
  const { ref, fontSize } = useFitText({
    ...options,
    onFinish: (finishedFontSize: number) => {
      setColor(undefined);
      if (options?.onFinish) options?.onFinish(finishedFontSize);
    },
  });
  return { ref, fontSize, color };
};

export default useBetterFitText;

from use-fit-text.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.