I have callback in interface:
JavaScript
x
5
1
interface {
2
onLoad?: () => void;
3
4
}
5
I tried to catch this callback using this:
JavaScript
1
2
1
props.onLoad(() => this.mapLoaded = true);
2
But I get this error:
Expected 0 arguments, but got 1.
Advertisement
Answer
It’s hard to say for certain without more context, but you’re probably meant to assign to onLoad
rather than call it:
JavaScript
1
2
1
props.onLoad = () => this.mapLoaded = true;
2
Typically, a callback is called by the object you’re passing the interface to, so that it can call back to your code when something happens (in this case, presumably when a map is loaded).