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

Update SimpleMap Component Example in README.md #251

Merged
merged 1 commit into from
May 10, 2016
Merged

Update SimpleMap Component Example in README.md #251

merged 1 commit into from
May 10, 2016

Conversation

joshburgess
Copy link
Contributor

@joshburgess joshburgess commented May 9, 2016

I may be missing something, but from what I could tell, the SimpleMap code example listed in the README file is not actually valid code... I was unable to get it working without bind() errors. It also heavily uses the 'this' keyword and .bind() despite being defined as a pure (stateless) functional component, which is uncommon and a little confusing (especially if someone were to define it using an arrow function without understanding how it differs).

I updated it to be more like the sample SimpleMap linked here:

https://github.com/tomchentw/react-google-maps_examples_simple-map/blob/493c95b5830a36434d648b9d7f779f231d2c79a5/src/scripts/SimpleMap.js

For now, I replaced the {...props} spread in GoogleMapLoader with {...props.containerElementProps}, as the click handlers are now being passed in as props too. I'm not sure if this is the best approach though...

If you don't like this solution (where everything needed is passed in as a prop), maybe the example should use an ES6 class instead of a pure function?

EDIT: I think I may have overlooked something and that's why I was having issues with the .bind() calls. Sorry for that. However, I do think getting rid of 'this' and 'bind()' would be ideal when using a functional component as an example. Also, we could go one step further and use destructuring assignment in the SimpleMap parameters to get rid of the props references.

I may be missing something, but from what I could tell, the SimpleApp code example listed in the README file is not actually valid code... I was unable to get it working without bind() errors. It also heavily uses the 'this' keyword and .bind() despite being defined as a pure (stateless) functional component, which is uncommon and a little confusing (especially if someone were to define it using an arrow function without understanding how it differs).

I updated it to be more like the sample SimpleMap linked here: 

https://github.com/tomchentw/react-google-maps_examples_simple-map/blob/493c95b5830a36434d648b9d7f779f231d2c79a5/src/scripts/SimpleMap.js

For now, I replaced the {...props} spread in GoogleMapLoader with {...props.containerElementProps}, as the click handlers are now being passed in as props too. I'm not sure if this is the best approach though...

If you don't like this solution (where everything needed is passed in as a prop), maybe the example should use an ES6 class instead of a pure function?
@tomchentw tomchentw merged commit a149d50 into tomchentw:master May 10, 2016
@tomchentw
Copy link
Owner

Thanks! The changes are great!

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

Successfully merging this pull request may close these issues.

2 participants