2

For example I could have a component

class HomeDefault extends PureComponent {
    ...
}

and I could add a property after the instance like so before the export

HomeDefault.someProperty = {test: 'test'}

Now if I were to use something like a higher order component over my HomeDefault component, I could console log out this "someProperty" object that I just set.

export default withHOC(HomeDefault)

// withHOC.js

import React from 'react';

const withHOC = Component => {
  const WithHOC = props => {
    console.log("the property: ", Component.someProperty) // this will work with the example above
    return <Component />;
  };

  return WithHOC;
};

export default withNavigation;

So THAT works, but I need a solution that can set this property from within a useEffect (for functional components) or a componentDidMount (for class)

Is this possible??

The actual use case is that I'm upgrading react navigation and the .navigationOptions property has been done away with but I'm trying to not completely redo our code for the time being. So it would be awesome t run a function in a useEffect/componentDidMount and set this property that way since navigationOptions doesn't make the navigation state available outside of the component.

I hope this all makes sense! thank you all

0 Answers0