Receiving/passing ref
See original GitHub issueHi! To continue our conversation at https://github.com/javivelasco/react-css-themr/pull/46
In 2.1.0 you added mapThemrProps
with example:
function mapThemrProps(props, theme) {
const { composeTheme, innerRef, mapThemrProps, themeNamespace, ...rest } = props;
return { ...rest, withRef: innerRef, theme };
}
But withRef
is usually boolean, for example in react-redux, so it doesn’t work.
It was case, when @themr
hoc wraps another hoc. But what if vice-versa, I have places where it’s wrapped by @connect
.
It used to be simple convention: In hoc’s ref handler function it checked if underline instance also has getWrappedInstance and used it to take ref from it, so it’s a chain when you can reach real component no matter how many hocs do you have on top of it
saveComponentRef(instance) {
this.instance = instance && instance.getWrappedInstance ? instance.getWrappedInstance() : instance;
}
But now having somewhere withRef
, somewhere innerRef
or mapThemrProps
I’m confused.
Feels like it has added complexity and problems instead of solving anything
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Forwarding Refs - React
Ref forwarding is an opt-in feature that lets some components take a ref they receive, and pass it further down (in other words,...
Read more >What's the proper way of passing a ref to a prop?
The ref will be an object with a current property. That property will be null until the element/component is mounted. Once it's mounted,...
Read more >What is Ref Forwarding? - In Plain English
React.forwardRef() takes a callback function and passes it two arguments, props and ref. You can write a quick helper function that receives ......
Read more >Using forwardRef in React to clean up the DOM
React forwardRef is a method that allows parent components pass down (i.e., “forward”) refs to their children. Using forwardRef in React gives ...
Read more >Forwarding refs to components - Mario Kandut
Ref forwarding in React means, that a reference through a component is automatically passed to one of its children. Typically, this is not ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The new ref forwarding api is coming to react
https://github.com/bvaughn/rfcs/blob/ref-forwarding/text/0000-ref-forwarding.md
https://reactjs.org/docs/forwarding-refs.html
I don’t believe that introduction of a new convention looks like a solution but still I agree that innerRef could be reverted back to withRef at least to be similar to other existing hocs.