I am trying to use ES6 template literal syntax to set sessionStorage where part of the key is the active tab id.
I attempted first to put the ES6 template literal within the method:
sessionStorage.getItem(`tabContent + ${this.props.activeTabKey}`)
But this wouldn't compile.
I next created a constant within my method and then referred to it within the sessionStorage method:
//attempt 1
const activeTabSessionStorageName = `tabContent + ${this.props.activeTabKey}`
(sessionStorage.getItem(`${activeTabSessionStorageName}`))
// attempt 2
const activeTabSessionStorageName = `tabContent + ${this.props.activeTabKey}`
sessionStorage.getItem(JSON.stringify(activeTabSessionStorageName))
//attempt 3
const activeTabSessionStorageName = `tabContent + ${this.props.activeTabKey}`
(sessionStorage.getItem(this.activeTabSessionStorageName))
I am not sure what would be the correct syntax but both failed and came up with the error:
SyntaxError: Unexpected token u in JSON at position 0
My goal is to have a way to dynamically check the storage to see if they key exists and then set it if not.
I am not that familiar with sessionStorage other than high level understanding. I know the key and the value have to be strings.
I am using React and Redux