-
I'm creating an interface Props extends React.HTMLProps<HTMLInputElement> {
...
}
// I know I need to use splitProps for this in solid =]
const Input = ({myProp, ...rest}) => {
...
return <input {...rest} />
} I'm wondering if there's an equivalent in SolidJS to extend the props of a native element |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Yes, |
Beta Was this translation helpful? Give feedback.
-
Follow up question: what is the best way to handle narrowing for a given input type? export const MyRangeInput: Component<JSX.HTMLAttributes<HTMLInputElement>> = (
props,
) => {
return (
<input
{...props}
type="range"
max={props.max}
/>
);
}; The typing for props here is clearly not specific enough Hoping to avoid re-typing this stuff manually: export const MyRangeInput: Component<{
max?: number;
min?: number;
} & JSX.HTMLAttributes<HTMLInputElement>> = (
props,
) => {
return (
<input
{...props}
type="range"
max={props.max}
/>
);
}; UpdateThis seems to work just fine :) export const MyRangeInput: Component<JSX.InputHTMLAttributes<HTMLInputElement>> = (
props,
) => {
return (
<input
{...props}
type="range"
max={props.max}
/>
);
}; For what it's worth, this difference feels a bit subtle and unintuitive. I wonder why these behave differently. JSX.HTMLAttributes<HTMLInputElement>
JSX.InputHTMLAttributes<HTMLInputElement> |
Beta Was this translation helpful? Give feedback.
Yes,
JSX.HTMLAttributes
from 'solid-js'.