I'm new react typescript developer, here i have a code which works in 'js' 'but when changed to 'tsx' getting error: Type 'Element' is not assignable to type 'string'.ts(2322) it is pointing to 'helperTextt' error (did not find answer else where) should i do : let helperTextt:any = ""; ?
any suggestions ?
let helperTextt = "";
if (event.target.id === "hostname") {
if (!HOSTNAME_REGEX.test(event.target.value)) {
helperTextt = (
<Trans i18nKey="form.formData.hostNameError">
Invalid Host name
</Trans>
);
errorr = true;
}
}
You could do
import { ReactElement } from "react";
and then
let helperTextt: ReactElement | null = null;
you can add type to your helperTextt variable
let helperTextt: JSX.Element = null;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With