0

I am following flux architecture and I want to know if it is possible to update the store based on the props received ? If yes what is the best method to do so ?

alwaysLearn
  • 6,882
  • 7
  • 39
  • 67
  • What do you mean by "the props"? You could update the store through a variety of methods which would all be acceptable. – WiredPrairie Mar 15 '15 at 12:05
  • @WiredPrairie By props I mean properties that will be passed from parent component to child component . – alwaysLearn Mar 15 '15 at 15:44
  • Could you show an example? A react component, if you're using the Flux patterns, would receive properties **from** a store. You could dispatch an action that updates a store if you'd like. But, I don't understand your scenario and why you'd do that? – WiredPrairie Mar 15 '15 at 16:13
  • @WiredPrairie Yes .. I know but I have a scenario where I need to update state from the property ..actually I am using one component for editing and adding .. and when adding I want to set all my checkboxes in component as checked .so in this case I want to update the store state on load on component property but can't figure out how to do ti – alwaysLearn Mar 15 '15 at 16:30

1 Answers1

0

Flux store is responsible for holding the data. The data should be updated by actions. On the other side, react view components get data from parents by props. So there is no props for stores!!

IcyBright
  • 654
  • 4
  • 15
  • ok let me explain the scenario . . I have one component that is being used for add and edit .In that component I need to show checkboxes to check the items( list of items is passed as property) .I am saving the state of the checkboxes to show which are checked and which are not .Now I want when component is being rendered in context of add , all items are checked by default.I know I can do this using prop itself but it that case the validation that I have applied to the state will not work.So it seems to me that it will be best if I can update the state with properties – alwaysLearn Mar 16 '15 at 06:01
  • It looks like one could achieve this by life cycle method getInitialState for that React component. So if the component is for add, all checkbox state will be initialized as checked. Otherwise will get object checked property. – IcyBright Mar 16 '15 at 12:27
  • update the state with properties - storing properties in your component state is an anti-pattern. – Jeremy D Mar 16 '15 at 20:27