To be able to fetch data for server-side rendering, it is recommended to setup a static method fetchData which will populate the Redux store through async actions.
When using connect the component is wrapped and is only accessible through WrappedComponent. However static methods are not accessible. The problem is further accentuated when using other HoC, such as reducerInjector. What is the recommended approach?
From the react-redux docs you see that connect uses hoistNonReactStatics (and if you look in the source code, you'll find it in connectAdvanced which is then extended by connect).
So if you're using connect, you should still have access to your own static methods. However, if you're using other HoCs, the static methods might not be copied over.
Another option is to make your static method a function
export default myFunction = () => { /* do stuff */ }
and import it where you need to use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With