PremKumar
PremKumar

Reputation: 1354

Storing values in sessionStorage in ReactJs

I have stored all the values in state called data as below:

loadValues = () => {
    this.setState({
      data: [`{"Price:" "${this.state.price}","Title": "${this.state.title}","MenuId": "${this.state.code}","Quantity": "${this.state.counter}"}`],
    })
  }

Now i need help in storing these values in sessionStorage and print it in console.(reactJs). Thanks in advance.

Upvotes: 1

Views: 9519

Answers (3)

Omid Nikrah
Omid Nikrah

Reputation: 2482

You can only do like the following:

loadValues = () => {
  this.setState({
    data: [`{"Price:" "${this.state.price}","Title": "${this.state.title}","MenuId": "${this.state.code}","Quantity": "${this.state.counter}"}`],
  }, () => {
    sessionStorage.setItem('data', this.state.data)
  })
}

Upvotes: 3

jsDevia
jsDevia

Reputation: 1292

It's not a question about reactJs. It's just javascript. use this

sessionStorage.setItem('key', 'value');

Upvotes: 3

Prafful Singh
Prafful Singh

Reputation: 31

u can use sessionStorage.setItem() to store values and sessionStorage.getItem() to get values

Upvotes: 3

Related Questions