I am trying to get my head around implementing redux into react. I understand the basics as to how stores, reducers and actions work. I am now trying to set up react-redux. I know there is quite a bit of documentation online, and as well as it is explained, it is slightly tricky to follow.
Here is what I have tried below, but it is not working. Can anyone spot some obvious mistake. I think I am close, but have made some small errors. Nothing is rendering on the screen at all.
Here is a jsiddle.
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import { connect } from 'react-redux';
function counter(state = 0, action) {
switch(action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
var store = createStore(counter);
const mapStateToProps = function(store) {
return {
count: store.getState()
};
}
class App extends React.Component {
increaseCounter() {
store.dispatch({
type: 'INCREMENT'
})
}
render() {
return (
<div>
<h1>Test</h1>
<h1>{this.props.count}</h1>
<button onClick={this.increaseCounter.bind(this)}>Click here </button>
</div>
)
}
}
connect(mapStateToProps)(App);
ReactDOM.render(
<App />
, document.getElementById('app')
);
this.increaseCount.bind(this)which should bethis.increaseCounter.bind(this). Please check into the code once.provideralso to get it to work withreact-redux?