2

I have gone through the git for SecureLS, but I find it difficult to define SecureLS in React.

var ls = new SecureLS({ encodingType: 'aes' })

How can I define like this in React.js class component?

technophyle
  • 7,972
  • 6
  • 29
  • 50
Ashrin Jose
  • 83
  • 2
  • 9

1 Answers1

1

With React class components, you can create instances of class within componentDidMount method in class components and store it in class variable

class App extends React.Component {
  componentDidMount() {
     this.ls = new SecureLS({ encodingType: 'aes' })
  }

}

Now you can use ls anywhere in your class with this.ls

P.S. Do keep in mind context issues whenever you use this.ls in class functions. The this inside class functions must refer to the class instance

Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400