setStatic function
I am trying to set a static function called fetch to be used with react-router-fetch but I can't seem to get it to work and cant find any examples about it.
I presume I use setStatic and have tried this:
const Testing = setStatic(
'fetch',
() => new Promise((resolve, reject) => {
setTimeout(resolve, 1000, { test: '1234' });
})
)(Content);
Any ideas if this is possible?
I got it working as above but there seems to be an issue with calling setStatic after withProps in compose
If you want the consumer of your component can access your static properties, you should wrap your components with setStatic in the last step, for example:
Do
compose(
setStatic(...),
withProps(...)
)(Content)
Instead of
compose(
withProps(...),
setStatic(...)
)(Content)
It's because withProps create and return a new component which doesn't have the setted static properties.
BTW if you want to hoist your static properties from the inner component to the outer component, you can use hoistStatics.