-
-
Save madetech-com/4fc710fe4d9a8078f7a73c207c18342c to your computer and use it in GitHub Desktop.
Pros and Cons of React + Redux
This file contains hidden or 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
{ type: 'ADD_COMMENT', comment: { body: 'test comment', user: 1 } } |
This file contains hidden or 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
import React from 'react' | |
import style from './style.css' | |
export default class CTAButton extends React.Component { | |
render () { | |
return ( | |
<a href={this.props.href} style={style}> | |
<h3>{this.props.title}</h3> | |
<span>{this.props.body}</span> | |
</a> | |
) | |
} | |
} |
This file contains hidden or 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
<CTAButton title="Shop Now" body="While stocks last!" href="/shop" /> |
This file contains hidden or 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
{ | |
tweets: [ | |
{ text: 'Interested in #ContinuousDelivery? Check out our new book!', user: 'madetech_com' }, | |
{ text: 'Join us tomorrow night for #QuizBuzz, a code-themed pub quiz - free to enter, prizes to win, food & drink provided', user: 'madetech_com' }, | |
{ text: 'Overstacked? The journey to becoming a full stack developer: https://t.co/cwEqxPM1sE', user: 'madetech_com' } | |
] | |
} |
This file contains hidden or 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
import React from 'react' | |
import { connect } from 'react-redux' | |
import store from './store' | |
import TweetList from '../components/TweetList' | |
class TweetDash extends React.Component { | |
render() { | |
return ( | |
<section> | |
<h1>Dashboard</h1> | |
// The 'tweets' section of state is passed to the component as a 'prop' | |
// You can pass this data down to sub-components | |
<TweetList tweets={this.props.tweets} /> | |
</section> | |
) | |
} | |
} | |
function mapStateToProps(state) { | |
// Redux diffs this against the full state internally to determine | |
// which parts of the state this component needs. It'll only re-render | |
// this component when these parts of the state change. | |
return { tweets: state.tweets } | |
} | |
export default connect(mapStateToProps)(TweetDash) |
This file contains hidden or 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
class LikeButton extends React.Component { | |
render () { | |
const text = this.props.liked ? 'Unlike' : 'Like' | |
return ( | |
<button onClick={::this.handleClick}> | |
{text} | |
</button> | |
) | |
} | |
handleClick (e) { | |
e.preventDefault() | |
// Proxy the onClick event to the component using this component. | |
// This is quite common when building re-usable components. | |
this.props.onClick(!this.props.liked) | |
} | |
} | |
<LikeButton liked={true} onClick={::console.log} /> |
This file contains hidden or 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
{ | |
"scripts": { | |
"start": "webpack-dev-server -d --history-api-fallback --hot --inline --progress --colors --port 3000", | |
"build": "NODE_ENV=production webpack --progress --colors" | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment