Ref not being passed between wrapped parent and child components
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 24.4k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 13
Description
Describe your context
dash 2.9.3
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-table 5.0.0
Describe the bug
Within custom components created using the dash-component-boilerplate, passing a Ref between a wrapped parent component and a wrapped child component does not work. An example setup looks like the below.
Tooltip.react.js
import React, { Component } from "react";
import PropTypes from "prop-types";
import { ExternalTooltipComponent } from "@somelibrary";
export default class Tooltip extends Component {
constructor(props) {
super(props);
}
render() {
const {id, setProps, children, ...rest} = this.props;
return (
<ExternalTooltipComponent
id={id}
{...rest}
>
{ children }
</ExternalTooltipComponent>
);
}
}
IconButton.react.js
import React, { Component, forwardRef } from "react";
import PropTypes from "prop-types";
import { ExternalIconButtonComponent } from "@somelibrary";
class IconButtonComponent extends Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
}
onClick() {
this.props.setProps({ n_clicks: this.props.n_clicks + 1 });
}
render() {
const {id, setProps, innerRef, ...rest} = this.props;
return (
<ExternalIconButtonComponent
id={id}
ref={innerRef}
onClick={this.onClick}
{...rest}
/>
);
}
}
const IconButton = forwardRef(function IconButton(props, ref) {
return <IconButtonComponent innerRef={ref} {...props} />;
});
export default IconButton;
Expected behavior
The Ref is available within the child component.
Notes
This may not be the best way of using forwardRef, particularly in the context of Dash. If there is a better or cleaner way to do this, I'd love to hear about it
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Tooltip.react.js and IconButton.react.js examples and the dash-component-boilerplate's wrapper and ref-handling entry points. Reproduce the nested wrapped parent/child case, trace where the ref stops being available, and verify that the child can access the expected ref without breaking Dash props behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100