Skip to content

Instantly share code, notes, and snippets.

@eduard-tkv
Created April 29, 2017 14:52
Show Gist options
  • Save eduard-tkv/3398470e8b86b37f9bbc68dd12bc42be to your computer and use it in GitHub Desktop.
Save eduard-tkv/3398470e8b86b37f9bbc68dd12bc42be to your computer and use it in GitHub Desktop.
//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