Here's the code Sandbox: https://codesandbox.io/s/lp005rj59q
I'm expecting it to display Hello Goodbye , but it's just showing Goodbye
I'm building the skeleton for a new React/Redux app that I'm working on and <h1>{value}</h1>
returns undefined. I know this because I put console.log(value) between my render and return method in my class.
I've Mapped State to props:
const mapStateToProps = state => ({
value: state.value
});
Created my store:
import { createStore } from "redux";
import reducers from "./reducers";
const store = createStore(reducers);
export default store;
Created my reducer with initial state of "Hello"
const initialState = {
value: "Hello"
};
function reducer(state = initialState, action) {
switch (action.type) {
default:
return state;
}
}
export default reducer;
created a connect function:
export default connect(
mapStateToProps,
mapDispatchToProps
)(Clock);
Added value to this.props:
export class Clock extends React.Component {
render() {
const { value } = this.props;
console.log(value);
return (
<div>
<h1>{value}</h1>
<h2> Goodbye</h2>
</div>
);
}
}
and passed the store to the provider element:
const AppWrapper = () => (
<Provider store={store}>
<Clock />
</Provider>
);
render(<AppWrapper />, document.getElementById("root"));
What am I missing?