arunoda / react-komposer

Feed data into React components by composing containers.
MIT License
733 stars 70 forks source link

Detect state change in composer function #86

Closed dulguun0225 closed 8 years ago

dulguun0225 commented 8 years ago

Is it possible to detect state change of a component in composer function?

arunoda commented 8 years ago

Could you give us more information on this?

dulguun0225 commented 8 years ago

As of now we can already detect props change inside a composer function, right? I was wondering if there could be same thing for state, but only read only access to component's state.

macrozone commented 8 years ago

React-komposer does not detect props-change, maybe there is a misunderstanding.

Additionally, you never have access from "outside" to a component's state, so that also makes little sense to me. Maybe you can explain what you want to achieve with this 👍

dulguun0225 commented 8 years ago

I wanted to shorten this chain "component -> action -> ReactiveDict -> container" into "component -> container".

For example if I wanted to set the ordering

  1. container sets action through useDeps
  2. component calls action
  3. action does the ReactiveDict.set('ordering', 'asc')
  4. container reads ReactiveDict.get('ordering')

this could be lot shorter if

  1. component does this.setState({ordering : 'asc'})
  2. container reads value of that state

I think that it wouldn't be a bad practice unless container gets write access to component's state.

clayne11 commented 8 years ago

I'm not following. Why do you need react-komposer if you're simply calling setState? You don't need to use react-komposer at all. Maybe you'd be better off with a library like recompose.

dulguun0225 commented 8 years ago

Need it to set parameter to subscription.

dulguun0225 commented 8 years ago

I guess people don't get it because I'm asking for what doesn't exist in React. Can higher order component read wrapped component's state?

macrozone commented 8 years ago

No. You can't read a component's state from outside. And that's a good thing.

With stateless components you "know" everything about your component anyway, because you pass everything as property

dulguun0225 commented 8 years ago

I thought if it is just a read access it would not be a bad practice