Skip to content
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

Please hoist statics in injectIntl #1047

Closed
mschipperheyn opened this issue Oct 11, 2017 · 2 comments
Closed

Please hoist statics in injectIntl #1047

mschipperheyn opened this issue Oct 11, 2017 · 2 comments

Comments

@mschipperheyn
Copy link
Contributor

Expected behavior

statics are hoisted

Current behavior

statics are not being hoisted
This is breaking stuff for some libraries such as react-navigation, that use:

class MyScreen extends React.Component{
    static navigationOptions = {
       [...]
    }
}

Solution

use hoist-non-react-statics as described here: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over

This issue is further described at react-navigation/react-navigation#332

An example solution can be viewed here:
https://github.com/ReactTraining/react-router/blob/master/packages/react-router/modules/withRouter.js

@ephys
Copy link

ephys commented Nov 10, 2017

As a temporary fix, people can use this custom injectIntl function instead of the one provided by react-intl:

import { injectIntl as baseInjectIntl } from 'react-intl';
import hoistNonReactStatic from 'hoist-non-react-statics';

/**
 * A fixed injectIntl that hoists statics.
 */
export function injectIntl(WrappedComponent: Function): Function {
  const WrapperComponent = baseInjectIntl(WrappedComponent);

  hoistNonReactStatic(WrapperComponent, WrappedComponent);

  return WrapperComponent;
}

@infiman
Copy link

infiman commented Mar 18, 2018

Having preload static method in my components for my SSR implementation, but injectIntl is not hoisting it after wrapping them. Any chance this will be fixed/implemented? Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants