formsy-react
formsy-react copied to clipboard
Warnings about refs when using functional components
I made a stateless functional component and exported it with withFormsy(Component). It works, but React prints warnings in the console:
"Stateless function components cannot be given refs. Attempts to access this ref will fail. Check the render method of Formsy(Component)"
Is there anything to do about this? I am not using refs in my component. It's me that doing something wrong or I can ignore it?
Yeah, it should be safe to use. withFormsy assigns a functional ref to the wrapped element which is equal to the innerRef prop you pass to it or a noop function if you don't pass anything.
We should definitely remove this default noop function, especially since the truthyness of the innerRef prop is checked before it is passed on to the wrapped component.
If you want to get rid of the warnings, just set the innerRef prop to null or false when using your component.
@MilosRasic damn that was fast. Thanks, it works.
I'm glad we have a work-around, but is this something we can fix in Formsy? Is there a way to check before passing down ref?
@rkuykendall do we want a PR to fix this? It seems to be easily achievable just removing the default noop function form the HOC
@almarto Yeah a PR would be appreciated. I don't think I understand the issue but it sounds like a simple fix.