As react supports it for now, inferno-compat should also support it.
@ritz078 Inferno 0.7 supported string refs but the amount of code to maintain them and the performance problems it brought with it weren't deemed necessary given the relative ease for a user to transition off of them to callback refs. Why? String refs require a constant tracking of parent components and their parents too, as a ref might be a child of a component and thus this makes it awfully sloppy to deal with.
You could totally use something like this: https://github.com/developit/linkref which would not only work in Inferno but also React and Preact. This wouldn't need any hacks etc and would be good on performance.
However, I could hack something in, a bit like how Preact has done it for it's compatibility layer. What are your thoughts?
I agree that this will have performance issues and even react doesn't encourage this way but I also believe that inferno-compat should be able to run existing code out of the box. That's the point of having this compatibility layer. But I agree that this way of using refs shouldn't be encouraged.
@ritz078 I almost wish there was an official codemod from FB that auto upgraded string refs to callbacks, would save so much pain in the long run!
totally agree
We had string support in core previously and it created a lot of complexity with it... :(
Whenever someone tries to use inferno compat in a large project , he may not want to make changes to his codebase as far as its supported by React. Maybe this is the reason preact implemented it ?
yes its valid point. Hopefully we can implement it so that it affects only Inferno-compat package
Yes. I will never want inferno to support it but inferno-compat should have it.
@ritz078 I'll try and add it tonight/tomorrow
Closing this ticket as its now implemented, crate new issue if problems found with it.
Is this fix already on npm? I tried both with 1.2.2 and 1.3.0-rc.3 and they both throw:
Uncaught Error: Inferno Error: string "refs" are not supported in Inferno 1.0. Use callback "refs" instead.
Thanks!
@landabaso you must use createElement API with inferno-compat to be able to use strong refs. Its legacy way of doing it anyway so better to use callbacks
Most helpful comment
Added to
dev- https://github.com/trueadm/inferno/commit/74e869b78ce3299dd19deb71a1f99191a25ee85a