You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
625 B

4 years ago
  1. package com.example.playscalajsreact.model
  2. import monocle.macros.Lenses
  3. import japgolly.scalajs.react.Reusability
  4. import japgolly.scalajs.react.Reusable
  5. @Lenses
  6. final case class Data(int: Int, str: String)
  7. object Data {
  8. implicit val reusability: Reusability[Data] = Reusability.derive
  9. // Here we wrap the lenses in Reusable.byRef so that React can compare setState/modState functions and know when its
  10. // it's got the same lens as a previous render. This is required to make [Method 1] work with Reusability
  11. object reusableLens {
  12. val int = Reusable.byRef(Data.int)
  13. val str = Reusable.byRef(Data.str)
  14. }
  15. }