arunoda / react-komposer

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

ReactiveVar doesn't work inside composeWithTracker ? #110

Closed crapthings closed 7 years ago

crapthings commented 7 years ago

i just want to make a toggler

ActionBar = ({ toggle, content }) => <div>
    <button onClick={() => toggle.set(true)}>new</button>
    {toggle.get() ? content() : ''}
</div>

function tracker(props, onData) {
    const toggle = new ReactiveVar(props.toggle || false)
    const content = function () { return 'actionbar need a content prop' }
    onData(null, { toggle, content })
}

C.ActionBar = container(tracker)(ActionBar)
crapthings commented 7 years ago

Ahhh forget about it, its my fault

crapthings commented 7 years ago

i think i should reopen this.

How to use ReactiveVar inside stateless component ?

clayne11 commented 7 years ago

Why are you using a ReactiveVar? React will automatically re-render the component when props change.

macrozone commented 7 years ago

I guess you want to toggle a state of the component.

In this case, a stateful component is a better fit with internal state that you toggle. OR even better: use https://github.com/acdlite/recompose withState