Home > OS >  storing UUid to firebase database
storing UUid to firebase database

Time:11-27

in my react application I am storing customer details in the firebase database successfully. while successfully doing this I am encountering problems storing ticket numbers using UUID. but I am generating the UUID in other components and visible in the front end. why I can't store it in firebase?


  cardinfoSubmitHandeler = (e) => {
    e.preventDefault();
    this.setState({
      infoDetails: false,
      cardGenerate: true,
      Passengerinfo: {
        ...this.state.Passengerinfo,
        ticketNumber: uuid().slice(0, 13).toString(),
      },
    });
    createTicket(this.state.Passengerinfo);
  };

all the data are stored from the state successfully but the ticket number. i have used tostring() to make it string but it didn't help.

CodePudding user response:

setState may be run asynchronously, but it accepts a callback function as a second argument that you can run after the state has been updated (and thus this.state.PassengerInfo includes your ticketnumber)

State changes might also be batched, if you're using state values it's better to pass on a function that accepts props, state https://reactjs.org/docs/state-and-lifecycle.html

  • Related