-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Allow connect() to hoist non-react statics from wrapped component #127
Conversation
…st statics from wrapped component. fixes #53
Allow connect() to hoist non-react statics from wrapped component
Out in 3.1.0. |
Hmm... The way greenkeeper references each PR with a hyperlink might get old. Do we really need to know about every public repo that merged this? |
I don't really mind. The references are because it mentions release notes which link to this PR. |
Yes, that's what I meant. It uses the commit text, which should reference issues and PRs it fixes/merges. I guess as long as it doesn't generate emails. 😄 |
This is sweet, but how do you get redux' state and dispatch in the static methods? I was hoping that since the static method is hoisted I could just get the connected component using Using it like this: // routes.jsx
<Route path="/" component={MyComponent} onEnter={MyComponent.onEnter}>
// MyComponent.jsx
class MyComponent extends Component {
static onEnter() {
// I need to access store.getState and store.dispatch here
}
render() {
// ...
}
} However weird it is to access instance specific stuff in a static method. It's making server-side rendering a lot easier when you can call component methods that dispatch actions before calling |
It's better to create a new issue than post in a not quite related one. Static methods don't have dispatch because it only exists in a specific rendering context. For example in a server rendered app you would render components with a different store instance on every request. This is why it doesn't make sense for static methods to have access to the dispatch function. What I think you can do is define Then you would call |
Sorry about that, found this PR after some searching and thought it was related enough since the hoisting is exactly what I was looking for. And yeah it did feel dirty abusing a static method like that, anyway I thought the method was hoisted to the connected component instance (and as such no longer static). I looked wrong though, it's still static so you're right... what I wanted doesn't make any sense. The |
hoist-non-react-statics