question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Receiving/passing ref

See original GitHub issue

Hi! 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:open
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

0reactions
raveclassiccommented, May 17, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found