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

Warnings about refs when using functional components #117

Open
ghost opened this issue Sep 26, 2018 · 5 comments
Open

Warnings about refs when using functional components #117

ghost opened this issue Sep 26, 2018 · 5 comments
Assignees

Comments

@ghost
Copy link

ghost commented Sep 26, 2018

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?

@MilosRasic
Copy link
Contributor

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.

@ghost
Copy link
Author

ghost commented Sep 26, 2018

@MilosRasic damn that was fast. Thanks, it works.

@rkuykendall
Copy link
Member

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 rkuykendall changed the title Warnings about refs when using functional components. Warnings about refs when using functional components Feb 22, 2020
@almarto
Copy link

almarto commented Feb 10, 2021

@rkuykendall do we want a PR to fix this? It seems to be easily achievable just removing the default noop function form the HOC

@rkuykendall
Copy link
Member

@almarto Yeah a PR would be appreciated. I don't think I understand the issue but it sounds like a simple fix.

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

No branches or pull requests

3 participants