ga-wdi-exercises / project4

[project]
https://github.com/ga-wdi-exercises/project4
2 stars 8 forks source link

quick react questions #542

Closed perryf closed 7 years ago

perryf commented 7 years ago

is the best ways to pass variables into a function that's attached to an element to pass them into an anonymous function? If I just write the function with the variable passed in, it will automatically call it.

<button onClick={(e) => {this.start(this.state.synth)}}>Start</button>

So here, passing this.state.synth into this.start function, this is the best way without auto calling the function when the page loads?

Also, what does registerServiceWorker(); do?

AndyWhitley commented 7 years ago

@perryf Yes, that is a good way to do this. It also preserves context, which, since we're using this, is important. One tip though is that you don't need the second set of brackets:

<button onClick={(e) => this.start(this.state.synth)}>Start</button>

As for the service worker, it is handling caching and other non-core functionality. Here's an interesting article that goes into more depth: https://medium.com/@addyosmani/progressive-web-apps-with-react-js-part-3-offline-support-and-network-resilience-c84db889162c

perryf commented 7 years ago

cool, thats Andy!