SolidJSS
SolidJS15mo ago
Vex

Why can I return a function from onMount?

Quick question:
I'm allowed to (as in "TypeScript allows me to") return a function from the function I declare inside onMount.
The docs does not comment on this (https://docs.solidjs.com/reference/lifecycle/on-mount), so what does it do? When is the returned function run?

Example:
    onMount(() => {
        const subscriptionID = props.plexer.subscribe(PLAYER_MOVE_EVENT, (event) => {
            if (
                event.playerID === props.backend.localPlayer.id
                && event.locationID === props.colonyLocation.locationID
            ) {
                setUserIsHere(true);
            }
        });

        return () => {
            props.plexer.unsubscribe(subscriptionID);
        }
    })
Was this page helpful?