Closed kidwm closed 7 years ago
Use this.state
instead. The render is a public method and components are usable outside hyperHTML too. State belongs to the instance, not to who invokes the render. Moreover, if you invoke the render you can pass whatever you want keeping this.state accessible.
P.S. if you really want to have a state
parameter, you can always define your render function as such:
class Clock extends hyper.Component {
get defaultState() { return {date: new Date()}; }
render(state = this.state) {
return this.html`
<div>
<h1>Hello, world!</h1>
<h2>It is ${state.date.toLocaleTimeString()}.</h2>
</div>`;
}
}
Got it, thanks for you explanation.
Pass state like in react, see react-future:
Or any other better use case?