digidem / react-dimensions

[Looking for maintainers]

Home Page:http://lab.digital-democracy.org/react-dimensions/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ref error when wrapping stateless functional component

atomanyih opened this issue · comments

If you use Dimensions to wrap a stateless functional component it complains but still seems to work.

const SomebodyCaresAboutDimensions = ({containerWidth} => (
  <div>
    width: {containerWidth}
  </div>
));

export default Dimensions()(SomebodyCaresAboutDimensions);

will give

Warning: Stateless function components cannot be given refs (See ref "wrappedInstance" in SomebodyCaresAboutDimensions created by DimensionsHOC). Attempts to access this ref will fail.

Thanks for this report. The ref is used for the instance method getWrappedInstance(), so I guess that method will not work for a stateless function component. Not sure what the solution is here, I'll leave this open and if anybody needs this method on a stateless function component they can look into it.

Just to clarify: this error means that the getWrappedInstance() method will not work for stateless functional components, but everything else should continue to function as normal.

We should do what redux does and make this opt-in: reduxjs/react-redux@2d3d0be

Would accept any pull-request that implements the same solution as the linked react-redux code.

Another approach would be to use a child function as react-virtualized/AutoSize is doing it
(It's providing the same feature with a different API).

Is it possible to merged this in?