Within my app.js I have my mapDispachToProps function ,which is supposed to send an action of type:increment to the reducer in the redux store. When the reducer receives it he is supposed to incremnet the initial state by 1.
In the heading component, which is a child of the app.js component I want to display the new value via mapStateToProps and this.props.value. The problem is it doesn`t work and I get no error message in the console.
When I do everything in the App.js it works very well.
What am I doing wrong?
Thanks in advance
My index.js
let store = createStore(increaseReducer);
ReactDOM.render(
<Provider store = {store}>
<App/>
</Provider>,
document.getElementById('root')
);
My store
export function increaseReducer(state = 0, action) {
if(action.type == "INCREMENT") {
return state+1;
}
else {
return state;
}
}
export default increaseReducer;
my app.js
import React, {Component} from 'react';
import{ connect }from 'react-redux';
import {Heading} from './components/heading';
class App extends Component {
constructor(props) {
super(props);
}
render() {
return (
<div className="App">
<Heading></Heading>
<button onClick={this.props.increment} > Counter</button>
</div>
);
}
}
let mapDispachToProps= {
increment:()=> {
return {type:"INCREMENT"}}
}
let AppContainer= connect(null,mapDispachToProps)(App);
export default AppContainer;
my heading.js
import React, {Component} from 'react';
import{ connect }from 'react-redux';
export class Heading extends Component {
constructor(props){
super(props);
}
render() {
return(
<h1>Click Counter: {this.props.value} </h1>
)
}
}
let mapStateToProps = (state)=>{return {
value: state
}}
let headingContainer = connect(mapStateToProps)(Heading);
export default headingContainer;