-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
subscribe directly to actions #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could you please provide an example so it's easier to reason about your question? |
OK, so how would you do map the following to the paradigm? const expandAll = ... (?)
class Expandable {
state = { expanded: false }
@autobind
toggleExpand(e) { this.setState({ expanded: !this.state.expanded }) }
render() { return (
<li>
<input type="checkbox" checked={this.state.expanded} onClick={this.toggleExpand}>
{this.state.expanded ? this.props.foo : '…'}
</li>
) }
}
class App {
render() { return (
<main>
<button onClick={expandAll}>Expand all</button>
<ol>
{this.props.bar.map(foo => <Expandable foo={foo}/>)}
</ol>
</main>
) }
} |
How is this related to Redux? You seem to be using React component state, not Redux. |
i use it elsewhere and all other actions apart from expandAll use and work with redux. alternatively i’d kinda have to store the expansion state of all |
I'd say leave it to React. The React approach would be to keep the toggled state of all components inside their shared parent ( |
hmm, makes sense. would be simpler to just subscribe each thanks! |
"Subscribing to action" breaks ideas of Redux because it makes your UI dependant on global event bus rather than current state. You can totally do that if you want, but it's not Redux. 😉 You can give IDs to expandables and keep something like |
ES6 coverage
hi, i have impure components with a checkbox to expand their contents, as well as an action to expand them all (as if clicked on each checkbox separately)
do i have to track all their states manually or is there a good way to subscribe to that action?
The text was updated successfully, but these errors were encountered: