It's All Writing.

Writing makes you happy.

How to provide utility functions for every components ( How to make HOC ( higher-order component ) ) at React Native


  • React Native
  • node


When there is a utility function you'd like to use in common during each components, you can do it easily via props by using HOC.
Using common.js which provides common utility functions has the fault as stateless and inaccessible to react native props.

Solution ( Code )

HOC ( withCommonProps ) provides each component with getLanguageCode and navigateTo function. In each component, you can use the HOC ( withCommonProps ) as below.