Giter VIP home page Giter VIP logo

Comments (2)

snelsi avatar snelsi commented on June 12, 2024 1

Hi Max,

I understand the challenges of maintaining a codebase with class components, especially when dealing with complex state and lifecycles.

As of version 10, the react-resize-detector no longer exports utils for working with class components, and the recommended approach involves the use of the useResizeDetector hook, which is designed for functional components.

You can create a functional wrapper component for ResizeDetector that encapsulates the hook logic and use it within your existing class components. Here's a basic example 👇

// Functional wrapper component with useResizeDetector hook
import React from 'react';
import { useResizeDetector, useResizeDetectorProps } from 'react-resize-detector';

const ResizeDetector = (props: useResizeDetectorProps<HTMLDivElement>) => {
  const { ref } = useResizeDetector(props);
  return <div ref={ref} style={{ width: '100%' }} />;
};

Additionally, if the migration to v10 proves challenging, you can simply stay on v9 until you find the time and resources to migrate your codebase to functional components. This way, you can continue to benefit from the library's functionality without immediate disruption.

Hope that helps. Feel free to reach out if you have any further questions.

from react-resize-detector.

Maximuschka avatar Maximuschka commented on June 12, 2024 1

Hi Roman,

thanks so much for the quick reply and given example. That is actually the same idea I was following yesterday, but was facing issues with the space the wrapper div is occupying. It was leading to positioning issues with the sibbling divs and generally the measurements of the actual target container were wrong.

But following your suggestion, I will continue trying to find a working solution. Worst case would mean I had to use absolute positioning of the wrapper in its parent div to allow for correct measurements of the target container and to avoid floating of its children.

Thanks again,
Max

from react-resize-detector.

Related Issues (20)

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.