quick react questions
Closed this issue · 2 comments
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?
@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
cool, thats Andy!