Shahar
Shahar

Reputation: 488

Maintining state on components in a Flux environment

We're using React and Flux (via the Alt implementation).

The state is maintained on the stores and is passed to the view components as props, which is nice for data.

I found myself, however, maintaining state such as isOnHover and similar UI states in the store as well, which seems cumbersome (creating action and store handlers for each UI state).

Is maintaining UI state directly on the component itself considered a bad practice, and if so, why?

Thanks.

Upvotes: 0

Views: 59

Answers (1)

AndyD
AndyD

Reputation: 895

Maintaining anything other than the data which the store provides in the respective store is bad practice in my opinion. One store for each piece of data. A components state should stay in the component.

Setting values like isOnHover should be stored and updated in the component, and initially set using getInitialState.

It's good to think of things like this in terms of using components across projects, you want to be able to essentially plug and play with minimal of fuss and code tangle for each component part.

Upvotes: 1

Related Questions