Reputation: 1354
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
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
Reputation: 1292
It's not a question about reactJs. It's just javascript. use this
sessionStorage.setItem('key', 'value');
Upvotes: 3
Reputation: 31
u can use sessionStorage.setItem() to store values and sessionStorage.getItem() to get values
Upvotes: 3