Skip to content

Commit

Permalink
Update refs element usage (#88)
Browse files Browse the repository at this point in the history
Update refs usage to new api and don't use string refs

https://reactjs.org/docs/refs-and-the-dom.html

"Legacy API: String Refs
If you worked with React before, you might be familiar with an older API where the ref attribute is a string, like "textInput", and the DOM node is accessed as this.refs.textInput. We advise against it because string refs have some issues, are considered legacy, and are likely to be removed in one of the future releases. If you’re currently using this.refs.textInput to access refs, we recommend the callback pattern instead."
  • Loading branch information
kunukn authored and redonkulus committed May 24, 2018
1 parent 243c4b2 commit 1881c6d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-stickynode",
"version": "1.4.1",
"version": "2.0.0",
"description": "A performant and comprehensive React sticky",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 4 additions & 6 deletions src/Sticky.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,8 @@ class Sticky extends Component {
updateInitialDimension (options) {
options = options || {}

var {outer, inner} = this.refs;

var outerRect = outer.getBoundingClientRect();
var innerRect = inner.getBoundingClientRect();
var outerRect = this.outerElement.getBoundingClientRect();
var innerRect = this.innerElement.getBoundingClientRect();

var width = outerRect.width || outerRect.right - outerRect.left;
var height = innerRect.height || innerRect.bottom - innerRect.top;;
Expand Down Expand Up @@ -383,8 +381,8 @@ class Sticky extends Component {
})

return (
<div ref='outer' className={outerClasses} style={outerStyle}>
<div ref='inner' className='sticky-inner-wrapper' style={innerStyle}>
<div ref={(outer) => { this.outerElement = outer; }} className={outerClasses} style={outerStyle}>
<div ref={(inner) => { this.innerElement = inner; }} className='sticky-inner-wrapper' style={innerStyle}>
{this.props.children}
</div>
</div>
Expand Down

0 comments on commit 1881c6d

Please sign in to comment.