-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(subcomponent): Correct bug with subComponent remounting between e…
…ach render
- Loading branch information
Luc Merceron
committed
May 1, 2017
1 parent
bc48394
commit 97764a7
Showing
8 changed files
with
93 additions
and
55 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
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
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,29 @@ | ||
import React from 'react' | ||
|
||
import warning from './warning' | ||
|
||
const getDisplayName = wrappedComponent => wrappedComponent.displayName || wrappedComponent.name | ||
const isStateless = component => !component.render && !(component.prototype && component.prototype.render) | ||
|
||
const NormalizeComponent = SchrodingerComponent => { | ||
const component = SchrodingerComponent | ||
let ComposedComponent = component | ||
|
||
// Managing component without state (functional component) | ||
if (isStateless(ComposedComponent)) { | ||
if (typeof component !== 'function') { | ||
warning('SizeFetcher has been called with neither a React Functional or Class Component') | ||
return null | ||
} | ||
ComposedComponent = class extends React.Component { | ||
render() { | ||
return component(this.props) | ||
} | ||
} | ||
ComposedComponent.displayName = getDisplayName(component) | ||
} | ||
|
||
return ComposedComponent | ||
} | ||
|
||
export default NormalizeComponent |
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