From 54bc126ce02d5a3582f98175e925e29c2ac1b159 Mon Sep 17 00:00:00 2001 From: Libor Olsak Date: Wed, 17 Jan 2018 15:29:57 +0100 Subject: [PATCH] Don't use inlined arrow functions in component props/attributes. It will create new function every time causing performance degradation in React applications. --- lib/AnimakitExpander.es6 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/AnimakitExpander.es6 b/lib/AnimakitExpander.es6 index 8dcfb56..1dc2916 100644 --- a/lib/AnimakitExpander.es6 +++ b/lib/AnimakitExpander.es6 @@ -16,6 +16,9 @@ export default class AnimakitExpander extends Component { duration: 0, }; + + this.setRootNode = this.setRootNode.bind(this); + this.setContentNode = this.setContentNode.bind(this); } componentWillMount() { @@ -233,6 +236,14 @@ export default class AnimakitExpander extends Component { } } + setRootNode(c) { + this.rootNode = c; + } + + setContentNode(c) { + this.contentNode = c; + } + render() { const { animation, expanded, prepare } = this.state; const showChildren = expanded || prepare || animation; @@ -240,11 +251,11 @@ export default class AnimakitExpander extends Component { return (
{ this.rootNode = c; }} + ref={this.setRootNode} style={ showChildren ? this.getRootStyles() : {} } >
{ this.contentNode = c; }} + ref={this.setContentNode} style={ showChildren ? this.getContentStyles() : {} } > { showChildren && hasChildren && this.getClearance() }