0

I have 4 kinds of elements in my database, I send it back in props, and I would like to use ${tickettype} as element to update in my database. So I don't know if I put the right symbols but I have an error on the first tickettype

fire
      .firestore()
      .collection("user")
      .doc(user.uid).update ({
        `${tickettype}`: `${tickettype} + ${ticketnumber}`
      });

enter image description hereThanks for time.

2
  • Could you please display the error? Commented Mar 11, 2021 at 20:32
  • Just added screen Commented Mar 11, 2021 at 20:32

2 Answers 2

1

In order to name an object's property based on the content of a variable, you should use the computed property names syntax:

{
  [tickettype]: `${tickettype} + ${ticketnumber}`
}
Sign up to request clarification or add additional context in comments.

Comments

0

Thanks solve for it, and I have another problem.

The second ${tickettype} come from props

const tickettype = location.state.tickettype;

[`${tickettype}`]: `${tickettype} + ${ticketnumber}`

But ${tickettype} is showing a data like that : "ticketadcopy" At the base ticketadcopy is a constant called in usestate from the firebase database

  const [tadcopy, setTAdcopy] = useState('');
  const [tvideos, setTVideos] = useState('');
  const [tdescriptions, setTDescriptions] = useState('');
  const [tthumbnails, setTThumbnails] = useState('');

For the moment, the function arrives in my database as "the value of the props ${tickettype} + a number from ${ticketnumber},

What I would like is that since ${tickettype} will return a value of type "ticketvideos", "ticketadcopy".... that it considers ${tickettype} as the constant tadcopy for example and that when I import to firebase, it gives me :

For example tadcopy = 5 and ${ticketnumber} = 3

5 + 3 = 8

For the moment, it shows me "tadcopy + 3

enter image description here

2 Comments

I don't understand exactly what you are trying to do. I can only advise you to give a look at template strings on MDN, and then open a new question if some code does not behave the way you expect: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
What I would like is that in my second ${tickettype} the ${tickettype} be considered as a raw text to be associated to the call of a state because the value of ${tickettype} makes one of my states

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.