Next.js Discord

Discord Forum

Adding custom events to all elements

Unanswered
Xander posted this in #help-forum
Open in Discord
Like how onClick is available on all html elements, is there a way to also add my own events?

5 Replies

Keyhole wasp
const CustomDiv = ({ children, someEvent, someClickEvent}) => {

    useEffect(() => {
        someEvent('for some reason')
    }, [])

    return <div onClick={someClickEvent}>{children}</div>
}


is this what you mean?
or do you want to add your own events to existing elements?
@Keyhole wasp or do you want to add your own events to existing elements?
well so I could do
<div onCustomEvent={}/>
Keyhole wasp
i don't believe you can do this out of the box
my answer is the react way to solve this problem structurally