You need to add parenthesis after return:
const CustomInput = ({children, value, onChange}: CustomInputProps) => {
return (
<div>
<label htmlFor="search">{children}</label>
<input id="search" type="text" value={value} onChange={onChange} />
</div>
)
}
https://stackblitz.com/edit/react-ts-pb6jpc?embed=1&file=index.tsx
If you are writing
const CustomInput = ({children, value, onChange}: CustomInputProps) => {
return
<div>
<label htmlFor="search">{children}</label>
<input id="search" type="text" value={value} onChange={onChange} />
</div>
}
this is transformed as
const CustomInput = ({children, value, onChange}: CustomInputProps) => {
return;
<div>
<label htmlFor="search">{children}</label>
<input id="search" type="text" value={value} onChange={onChange} />
</div>
}
so you function basically returns undefined
and is interpreted as
const CustomInput = ({children, value, onChange}: CustomInputProps) => {
return undefined;
// nothing after return counts
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…