Reactjs 使用动态(基于uid的)路径反应Redux MapStateTrops
我是一个新的反应和反应。我试图根据用户id使用动态路径通过“MapStateTops”。使用的基本代码如下:Reactjs 使用动态(基于uid的)路径反应Redux MapStateTrops,reactjs,react-redux,mapstatetoprops,Reactjs,React Redux,Mapstatetoprops,我是一个新的反应和反应。我试图根据用户id使用动态路径通过“MapStateTops”。使用的基本代码如下: const mapStateToProps = (state) => { console.log(state); console.log(state.firebase.auth.uid); <===== THIS DISPLAYS THE USERS ID, PROVING THE PATH EXISTS return { cou
const mapStateToProps = (state) => {
console.log(state);
console.log(state.firebase.auth.uid); <===== THIS DISPLAYS THE USERS ID, PROVING THE PATH EXISTS
return {
courses: `state.firestore.ordered.${state.firebase.auth.uid}`, <======= THIS LINE IS AN ERROR EVEN THOUGH THE PATH EXISTS
}
}
const-mapStateToProps=(state)=>{
console.log(状态);
log(state.firebase.auth.uid);若要访问JS对象中的动态属性,需要使用方括号
courses: state.firestore.ordered[state.firebase.auth.uid]
课程:state.firestore.ordered(`nameofurstable/${state.firebase.auth.uid}`);你能试试这个并检查一下吗,对我来说,似乎有一个语法错误阻止了你想要的结果。谢谢你的建议。不幸的是,这不起作用。非常感谢!:)我知道这很简单,并且尝试了各种语法,但不是这个!
courses: state.firestore.ordered[state.firebase.auth.uid]