How do I use React redux without react router?
How does this provider stuff work?
Hi @ccorcos, have you seen this? Check out the Connecting to Redux section.
If that doesn't answer your question, could you be a little more specific?
<Provider> puts store to be available on React context.
It doesn't do anything else and isn't related to routing.
Interesting. I've had to deal with piping tons of props from a top-level component all the way through. I think using the splats with props is easy enough though...
If my understanding is correct, then I can create my own provider something like this:
let Provider = React.createClass({
componentWillMount: function() {
this.unsubscribe = this.props.store.subscribe(() => {
this.setState(this.props.store.getState())
})
},
componentWillUnmount: function() {
this.unsubscribe()
},
render: function() {
let Component = this.props.component
return (
<Component {...this.state}/>
)
}
})
React.render(
<Provider store={store} component={App}/>,
document.getElementById('root')
)
I'm missing your point.
What you seem to be describing is what connect() does. <Provider> itself just puts store in context so connect() can read it regardless of how deeply nested the component is in view hierarchy. You can use connect() without <Provider> as long as you pass store down manually via props; <Provider> is what lets you avoid this manual threading.
What's your use case?
Ah. I see. My use case is that I'm just trying to understand Redux. I want to know whats really going on before I use all these magical functions.
I think I get it now though. Provider just makes store available via context. And connect does all the subscription stuff, piping store.getState() to props.