Differences between :init-state vs :state at build function
Asked Answered
P

1

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.

Pasteurize answered 9/6, 2014 at 15:18 Comment(0)
V
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.

Ventriculus answered 10/6, 2014 at 14:13 Comment(1)
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)Ventriculus

© 2022 - 2024 — McMap. All rights reserved.