This repository has been archived by the owner on Sep 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Pure component notes #292
Merged
dvdzkwsk
merged 2 commits into
dvdzkwsk:master
from
justingreenberg:pure-component-notes
Dec 14, 2015
Merged
Pure component notes #292
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
import React from 'react' | ||
import 'styles/core.scss' | ||
|
||
export default class CoreLayout extends React.Component { | ||
static propTypes = { | ||
children: React.PropTypes.element | ||
} | ||
|
||
render () { | ||
return ( | ||
<div className='page-container'> | ||
<div className='view-container'> | ||
{this.props.children} | ||
</div> | ||
// Note: Stateless/function components *will not* hot reload! | ||
// react-transform *only* works on component classes. | ||
// | ||
// Since layouts rarely change, they are a good place to | ||
// leverage React's new Statelesss Functions: | ||
// https://facebook.github.io/react/docs/reusable-components.html#stateless-functions | ||
// | ||
// CoreLayout is a pure function of it's props, so we can | ||
// define it with a plain javascript function... | ||
function CoreLayout ({ children }) { | ||
return ( | ||
<div className='page-container'> | ||
<div className='view-container'> | ||
{children} | ||
</div> | ||
) | ||
} | ||
</div> | ||
) | ||
} | ||
|
||
CoreLayout.propTypes = { | ||
children: React.PropTypes.element | ||
} | ||
|
||
export default CoreLayout |
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,12 +1,16 @@ | ||
import React from 'react' | ||
import { Link } from 'react-router' | ||
|
||
const AboutView = () => ( | ||
<div className='container text-center'> | ||
<h1>This is the about view!</h1> | ||
<hr /> | ||
<Link to='/'>Back To Home View</Link> | ||
</div> | ||
) | ||
export class AboutView extends React.Component { | ||
render () { | ||
return ( | ||
<div className='container text-center'> | ||
<h1>This is the about view!</h1> | ||
<hr /> | ||
<Link to='/'>Back To Home View</Link> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default AboutView |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because the test utils don't work with pure components yet, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly... do you want me to revert this commit to leave this as component class too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at all, was just making sure. And I'm not totally caught up to speed here: A regular React component class rendered inside of a pure component will still work w/ HMR, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davezuko yes all transforms are working, see below. i also tested hmr with multiple nested
AboutView
s to be sure react-transform is walking the full component tree 👍There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be amazing, and thanks for all the gifs, they help a lot!