Created
September 5, 2016 02:48
-
-
Save treshugart/64934c76d6ab18a07adaf53c7af0e031 to your computer and use it in GitHub Desktop.
SkateJS stateless function for doing stuff with slotted nodes on first render and subsequent renders (slotchange event only fires on updates)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $slotRendered = Symbol(); | |
const Slot = (props, chren) => { | |
const { changed } = props; | |
function onSlotchange(e) { | |
const slot = e.target; | |
if (slot[$slotRendered]) { | |
if (changed) { | |
changed(slot); | |
} | |
} else { | |
slot[$slotRendered] = true; | |
} | |
} | |
function ref(slot) { | |
if (!slot[$slotRendered]) { | |
changed(slot); | |
} | |
} | |
return <slot onSlotchange={onSlotchange} ref={ref}>{chren()}</slot>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment