Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ export default GoogleApiWrapper({
})(MapContainer)
```

Alternatively, the `GoogleApiWrapper` Higher-Order component can be configured by passing a function that will be called with whe wrapped component's `props` and should returned the configuration object.

```javascript
export default GoogleApiWrapper(
(props) => ({
apiKey: props.apiKey,
language: props.language,
}
))(MapContainer)
```

If you want to add a loading container _other than the default_ loading container, simply pass it in the HOC, like so:

```javascript
Expand Down
6 changes: 3 additions & 3 deletions src/GoogleApiComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ const defaultCreateCache = options => {

const DefaultLoadingContainer = props => <div>Loading...</div>;

export const wrapper = options => WrappedComponent => {
const createCache = options.createCache || defaultCreateCache;

export const wrapper = input => WrappedComponent => {
class Wrapper extends React.Component {
constructor(props, context) {
super(props, context);
const options = typeof input === 'function' ? input(props) : input;

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

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

const createCache = options.createCache || defaultCreateCache;

this.scriptCache = createCache(options);
this.scriptCache.google.onLoad(this.onLoad.bind(this));
Expand Down