6

I understand that you can initiate the state of a component by passing a map as the value of the :init-state keyword. But by passing this map as the value of the :state keyword, for example, between a component and its child component, now they can share that same state? Is that it? Thanks.

roboli
  • 1,418
  • 20
  • 24

1 Answers1

5

The difference is when the childs state gets set.

  • :init-state is only set once, when the component is mounted.
  • :state is set on each render.

Therefore, :init-state should be used to (as the name suggests), initialise the state. On the other hand, :state is used to set state that changes over time.

  • Bit late, I know, especially with Om Next and all, but I should probably have said that :state is used for a parent to control the child's state (not to change state on a particular trigger. `om/set-state!` can be used for that purpose) –  Oct 21 '16 at 14:33