scommons.react.test.TestErrorBoundary.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scommons-react-test_sjs0.6_2.13 Show documentation
Show all versions of scommons-react-test_sjs0.6_2.13 Show documentation
Core Scala.js, React.js testing utilities
The newest version!
package scommons.react.test
import scommons.react._
import scala.scalajs.js
object TestErrorBoundary extends ClassComponent[Unit] {
private case class TestErrorBoundaryState(error: Option[js.Object] = None)
protected def create(): ReactClass = createClass[TestErrorBoundaryState](
getInitialState = { _ =>
TestErrorBoundaryState()
},
componentDidCatch = { (self, error, _) =>
self.setState(TestErrorBoundaryState(Option(error)))
},
render = { self =>
self.state.error match {
case None => self.props.children
case Some(error) =>
<.div()(
s"$error"
)
}
}
)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy