-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: apply saveref as render children
- Loading branch information
Showing
6 changed files
with
69 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
|
||
export default class SaveRef extends React.Component { | ||
getRef = (name) => { | ||
return this[name]; | ||
} | ||
|
||
saveRef = (name) => { | ||
return (node) => { | ||
if (node) { | ||
this[name] = node; | ||
} | ||
}; | ||
} | ||
|
||
render() { | ||
return this.props.children(this.saveRef, this.getRef); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
import React from 'react'; | ||
import TabBarRootNode from './TabBarRootNode'; | ||
import TabBarTabsNode from './TabBarTabsNode'; | ||
import SaveRef from './SaveRef'; | ||
|
||
export default class TabBar1 extends React.Component { | ||
saveRef = (name) => { | ||
return (node) => { | ||
if (node) { | ||
this[name] = node; | ||
} | ||
}; | ||
} | ||
|
||
render() { | ||
return ( | ||
<TabBarRootNode saveRef={this.saveRef} {...this.props}> | ||
<TabBarTabsNode saveRef={this.saveRef} {...this.props} /> | ||
</TabBarRootNode> | ||
<SaveRef> | ||
{(saveRef) => ( | ||
<TabBarRootNode saveRef={saveRef} {...this.props}> | ||
<TabBarTabsNode saveRef={saveRef} {...this.props} /> | ||
</TabBarRootNode> | ||
)} | ||
|
||
</SaveRef> | ||
); | ||
} | ||
} |