Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

How do I create a custom input svelte component and reuse prop types?

$
0
0

I'm trying to create a wrapped version of an input component with a label, I want it to have all the same attributes as the normal input field, as well as the "label".

I'm slightly confused about how to import the type definition and to type the attributes properly.

<style>    input {        width: 100%;        display: block;    }</style><script lang="typescript">    import { SvelteInputProps } from 'svelte'    export let label: string = ''    type $$Props = SvelteInputProps;</script><label>    {label}<input {...$$props} /></label>

like this in react:

interface Props extends React.InputHTMLAttributes<HTMLInputElement> {    label: string}export default function Input (props: Props) {    const { label, ...inputProps } = props;    return (<label>            {label}<input {...inputProps}></input></label>    )}

Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>