Answer the question
In order to leave comments, you need to log in
Why doesn't the state come to connect()()?
I have a store, with a reducer, in which, by clicking on a button, I will dispatch the corresponding action. Everything works here.
Then I sign the other component like this:
const matchStateToProps = (state)=>{
return {
title: state.title,
text: state.text
}
}
export default connect(matchStateToProps)(Notes)
TypeError: Cannot read property 'title' of undefined, the error is in
return {
title: state.title,
text: state.text
}
const matchStateToProps = (state)=>{
if(!state) return {}
return {
title: state.title,
text: state.text
}
}
export default connect(matchStateToProps)(Notes)
import {createStore} from 'redux'
const notesReducer = (state = {text: "", title: ""}, action)=>{
console.log(state)
switch(action.type){
case "ADD_NOTES":
return {...state, "text" :action.text, "title":action.title}
break;
case 'NOTE_DID_LOAD':
return {state}
break;
default:
console.log("Unreal dispatching ", action)
}
}
export default createStore(notesReducer);
Answer the question
In order to leave comments, you need to log in
default:
return state;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question