-
Is it possible to use the It seems like it only works for built-in html tags like I wanted to use a similar validation logic like in the forms example (https://www.solidjs.com/examples/forms) but on a custom |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
No it is not currently possible. Components have no instance to attach to, and |
Beta Was this translation helpful? Give feedback.
-
Hello, Is there any news about this ? |
Beta Was this translation helpful? Give feedback.
-
I am experimenting with Solid JS and just encountered this issue. This is conceptually unexpected behavior that doesn't seem to make sense.
The current behavior (Solid 1.8) is to silently discard the use directive with no error or warning. It seems like, if the first two points are true, that we can sidestep the sugaring and everything should work fine. I don't know if this is true in general, but it certainly works in my limited test (below). I don't know enough of the model to understand why this isn't suitable behavior for the general case, but something in the documentation/code doesn't match up here. import { render } from "solid-js/web";
import { createSignal } from "solid-js";
function defaultValue(el) {
el.value = "success";
}
function CustomInput(props) {
return (
<input {...props} />
);
}
function App() {
return (
<div>
Native <input use:defaultValue />
<br/>
Sugar <CustomInput use:defaultValue />
<br/>
Ref <CustomInput ref={el => defaultValue(el)} />
</div>
)
}
render(() => <App />, document.getElementById("app")!); |
Beta Was this translation helpful? Give feedback.
No it is not currently possible. Components have no instance to attach to, and
use
uses an in scope compiler trick to get the directive which isn't possible for out of scope things like other files or even spread handling. This comes with the territory on this approach and why Svelte also doesn't supportuse
directives on their Components.