the code
const Question = () => {
const idd = useSelector(state => state.idd)
const questions = useSelector(state => state.questions)
console.log(questions)
console.log(idd)
return(
<>
</>
)
}
const mapStateToProps = ({ authedUser, questions, users }, { id }) => {
const idd = id
console.log(idd)
return {
authedUser,
questions,
users,
idd
}
}
the result of console.log(questions) print questions
the result of console.log(idd) is udefined
can you help me please?
CodePudding user response:
i just get it from props directly by adding props to Component=(props) and console.log(props.id)
CodePudding user response:
It doesn't look like something named "idd" was ever part of your Redux store? In that case, yes, it is completely normal to get undefined
here - useSelector
only gives you access to your Redux store.
useSelector
has nothing to do with mapStateToProps
(that just maps state to props, as the name implies) and you should not use useSelector
and connect/mapStateToProps
together and prefer useSelector
whenever possible.