-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Equivalent of @solid-primitives/refs mergeRefs
but for event listeners
#546
Comments
love this idea +1, for one of my project I had to make a hacky mergeCallbacks for this sorta of stuff I wonder if it makes sense that this goes into @solid-primitives/props as well, like the combineStyle |
what I am using right now is const onInput = () => {
if (local.value && context) {
context.setSelected(local.value);
}
};
createEventListener(() => ref, "input", onInput); This way I don't worry about the consumer overriding my events, seems like a better solution than hacking around with very custom stuff |
+1 to just adding a bit of custom logic when needed if ("onClick" in props) props.onClick(e)
localOnClick(e) And for doing that automatically for all props, But I like the idea of the onClick={chain(
e => console.log("click:", e),
props.onClick,
)} |
@thetarnav oh wow, did not know about |
I'd agree it's easier, but the problem with that is that you will have to override the handler types from ComponentProps if you do this, because its types allow for bound event handlers. Does chain handle those as well? |
Good point @gabrielmfern, it does not. |
Describe The Problem To Be Solved
Hi, so when I am creating components almost always I need to pass some callbacks to
onClick
or anything else like that, but I want the user of the component to be able to passonClick
as well, so now I need to pass that event tosplitProps
, and don't forget to pass bothonClick
andonclick
because both variants could be used by the component user and then finally check if it is a function and then call it with the same params.Doing this everytime is a burden.
Suggest A Solution
How I think about solving the problem:
splitProps
function from solid, as you would always use splitProps to get the callbacksMy very rough first try at implementing this:
usage: https://playground.solidjs.com/anonymous/96db2b0c-0846-47ed-86ef-0e275c4b24e7
The text was updated successfully, but these errors were encountered: