Mobx.dart: When to use stateless widget and stateful widget

Created on 26 Apr 2019  路  3Comments  路  Source: mobxjs/mobx.dart

Hi, In the getting started example you use stateless widget but in the examples (TODO, HackerNews, etc ). you use stateful widget. May I know when to use stateless widget and stateful widget?

discussion

Most helpful comment

Ah nice find @campanagerald. In general always use StatelessWidgets as the stores would be outside of the Widget. If the Store is tied to the lifecycle of the Widget, then go for a StatefulWidget

All 3 comments

Ah nice find @campanagerald. In general always use StatelessWidgets as the stores would be outside of the Widget. If the Store is tied to the lifecycle of the Widget, then go for a StatefulWidget

@pavanpodila, is there any example where Store is tied to the lifecycle of the Widget?

The Todo example is using that idea. It creates the store in a StatefulWidget and is alive only for the lifetime of the Todo route page.

https://github.com/mobxjs/mobx.dart/blob/master/mobx_examples/lib/todos/todo_widgets.dart

Was this page helpful?
0 / 5 - 0 ratings