-
Notifications
You must be signed in to change notification settings - Fork 813
Allow GoogleApiWrapper() HOC to be initialized with data from props #172
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
Allow GoogleApiWrapper() HOC to be initialized with data from props #172
Conversation
I <3 this feature! Can you add a bit to the README describing this? |
…nctions-as-input # Conflicts: # README.md # src/GoogleApiComponent.js
Absolutely. I added the simple example of the alternative configuration to the README. Also noticed I had based my branch on an old version of master. It should be free of conflicts now. Edit: Oh well no wonder I was based on an old version - you pushed like 700 commits today ;) |
class Wrapper extends React.Component { | ||
constructor(props, context) { | ||
super(props, context); | ||
const options = typeof input === 'function' ? input(props) : input; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea, but I think that it's worth to rebuild it on props change as well. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Wanna add a PR @rangoo94?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, I will do it today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added PR with update: #178
#172 improvement: Allow Google HOC to be initialized from props
Thank you very much @rangoo94. My approach was indeed not complete. |
No problem, you're welcome :) |
This pull requests enhances the GoogleApiWrapper HOC by the possibility to initialize it with data from props by accepting a function as argument when initializing the HOC. The function will be called by the HOC by passing it the props passed to the HOC.
This solution inspired by the recompose bundle (e.g. the HOC withProps()) and is completely backwards compatible.
With this change, the GoogleApiWrapper can be used the same way as before:
Additionally it can be initialized with a function as described above:
Or, as in our case, the HOC can be used with redux and recompose: