0

I am new to React and React-Redux. I'm trying to pass "mapStateToProps" using a dynamic pathway depending on the users id. The basic code being used follows:

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

    }
}

The code works fine if I manually type in the users ID. Lets say the users ID is "12345", then replacing that line with

courses: state.firestore.ordered.12345, <======= THIS LINE WOULD WORK

Any clarification as to why this doesn't work and an alternative method of making this work would be greatly appreciated!

Andrew B.
  • 245
  • 3
  • 12
  • courses: state.firestore.ordered(` nameofuserstable/${state.firebase.auth.uid} `); can you try this and check, for me looks like there is a syntax error that is preventing the result you want. – Hasan Patel Jul 21 '20 at 18:40
  • Thanks for the suggestion. Unfortunately that did not work. – Andrew B. Jul 21 '20 at 18:49

1 Answers1

1

If you want to access dynamic property in JS object, you need to use square braces

    courses: state.firestore.ordered[state.firebase.auth.uid]
dkuznietsov
  • 298
  • 1
  • 9