Created
April 29, 2017 14:52
-
-
Save eduard-tkv/3398470e8b86b37f9bbc68dd12bc42be to your computer and use it in GitHub Desktop.
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
//App.js | |
import React, { Component } from 'react'; | |
import {incrementCount} from '../actions'; | |
export default class App extends React.Component { | |
constructor(props){ | |
super(props); | |
this.state = { | |
count: props.store.getState() | |
}; | |
this.handleClick = this.handleClick.bind(this); | |
this.handleChange = this.handleChange.bind(this); | |
} | |
componentDidMount(){ | |
this.props.store.subscribe(this.handleChange); | |
} | |
handleChange(){ | |
this.setState({ | |
count: this.props.store.getState() | |
}); | |
} | |
handleClick(){ | |
this.props.store.dispatch(incrementCount()); | |
} | |
render(){ | |
return ( | |
<div> | |
<p>Count: {this.state.count}</p> | |
<button onClick={this.handleClick}>Increment</button> | |
</div> | |
); | |
} | |
} | |
//index.js | |
import React, { Component } from 'react'; | |
import ReactDOM from 'react-dom'; | |
import App from './components/App'; | |
import { createStore } from 'redux'; | |
import reducer from './reducers'; | |
let store = createStore(reducer); | |
ReactDOM.render(<App store={store}/>, document.getElementById('app')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment