Skip to content
This repository was archived by the owner on Jun 3, 2020. It is now read-only.

Conversation

@BDav24
Copy link
Contributor

@BDav24 BDav24 commented Feb 14, 2017

Hi @balloob,

This PR is to remove the call to findDOMNode, because the use of this function is discouraged.
Instead I used a ref callback (available since react@0.13: https://twitter.com/dan_abramov/status/584125325212307456?lang=en).

(My initial need is for snapshot testing with jest: facebook/react#8989)

Thanks!


saveSidebarWidth() {
const width = ReactDOM.findDOMNode(this.refs.sidebar).offsetWidth;
const width = this.sidebar.offsetWidth;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

src/sidebar.js Outdated
<div {...rootProps}>
<div className={this.props.sidebarClassName} style={sidebarStyle} ref="sidebar">
<div className={this.props.sidebarClassName} style={sidebarStyle}
ref={node => (this.sidebar = node)}>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should cache this function on the instance to avoid recreating this method on each invocation of render

src/sidebar.js Outdated

saveSidebarWidth() {
const width = ReactDOM.findDOMNode(this.refs.sidebar).offsetWidth;
const width = this.refs.sidebar.offsetWidth;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

@BDav24
Copy link
Contributor Author

BDav24 commented Feb 15, 2017

@balloob I made it even simpler.

@balloob
Copy link
Owner

balloob commented Feb 15, 2017

String refs are considered a legacy API and support will be removed to the future. The function was the right choice https://facebook.github.io/react/docs/refs-and-the-dom.html#legacy-api-string-refs

src/sidebar.js Outdated
this.onScroll = this.onScroll.bind(this);
}

saveSidebarRef = (node) => this.sidebar = node;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class properties must be methods. Expected '(' but instead saw '='.
'function closure expressions' is only available in Mozilla JavaScript extensions (use moz option).
Expected an identifier and instead saw '=>'.
Class properties must be methods. Expected '(' but instead saw '.'.

@balloob
Copy link
Owner

balloob commented Feb 15, 2017

Nice! Ok to merge when ESLint fixed (see build failure)

@BDav24
Copy link
Contributor Author

BDav24 commented Feb 15, 2017

Sorry for the linting, I edited strait on github :)

@balloob balloob merged commit 17eafd6 into balloob:master Feb 15, 2017
@BDav24 BDav24 deleted the remove-finddomnode branch February 16, 2017 08:51
@BDav24
Copy link
Contributor Author

BDav24 commented Feb 16, 2017

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants