smart-rename for React forwardRef
(+ remove layer of indirection on destructuring assignment)
#48
Labels
enhancement
New feature or request
It would be cool if
smart-rename
was able to handle React'sforwardRef
:Based on that example, we can see that the 2nd param of the React component passed to the
forwardRef
function is theref
being forwarded; which we can then use within thesmart-rename
.Looking at my sample webpack'd code (Ref), after using the CLI to unpack it to
./496-unpacked
, and then unminify it to./496-unminified
:Looking at
module-10604.js
, we can see that it's a React component usingforwardRef
:Unpacked:
Unminified:
If we had a
smart-rename
for this, then we could renamee
toeProps
(or justprops
), andt
totForwardedRef
(or justforwardedRef
), and the unminified output could look something more like this:This could be improved even further if we removed the layer of indirection on the destructuring assignment on the import of
l
, as well as the React component propse
(which might be a bug/edge case limitation ofsmart-inline
, as I would have expected it to do it)With that, the output could look more like:
(Note: I'm not 100% sure if we can safely fold the
l.forwardRef
into the import like I showed in my above example, as it doesn't seem to use the(0, l.useEffect)
style call pattern.. but as far as how it would be used in real world code.. my above example is fairly canonical)The text was updated successfully, but these errors were encountered: