Calling an event only once
andreighh opened this issue · 3 comments
andreighh commented
Hello,
Is it possible to call an event only once for the map (map.once("rendercomplete"...
)? I'm trying to use onRenderComplete
but I want it to run only once. Thank you.
mmomtchev commented
You should do it the React way - by adding state to your component and setting that handler based on the state.
This is the React way of doing things.
mmomtchev commented
First:
const [called, setCalled] = React.useState(false);
Then:
<.... onRenderComplete={called ? undefined : yourHandler} ... >
And in the handler:
setCalled(true)
andreighh commented
I was thinking it's not the right way, but I see I'm wrong, thank you for the help and your time.