Trabajando en React tengo este problema....
Tengo el siguiente componente:
const VolcanoDateField = (props) => {
const { date, format } = props;
const { i18n } = useTranslation();
const datetime = new Date(date);
const getDateString = (short) => {
let stringDate = "";
if (datetime !== undefined) {
stringDate = Intl.DateTimeFormat(i18n.language, {
timeZone: "Europe/London",
year: "numeric",
month: short ? "2-digit" : "long",
day: "2-digit",
}).format(datetime);
}
return stringDate;
};
const getTimeString = () => {
let stringTime = "";
if (datetime !== undefined) {
stringTime = Intl.DateTimeFormat(i18n.language, {
timeZone: "Europe/London",
hour12: false,
hour: "numeric",
minute: "numeric",
second: "numeric",
}).format(datetime);
}
return stringTime;
};
const buildObjectFromDate = () => {
switch (format) {
case constants.SHORT_DATETIME:
return (
<div>
{getDateString(true)}
<br />
{getTimeString()}
</div>
);
break;
case constants.LONG_DATETIME:
return (
<div>
{getDateString(false)}
<br />
{getTimeString()}
</div>
);
break;
case constants.ONLY_DATE:
return <div>{getDateString(true)}</div>;
break;
case constants.ONLY_LONG_DATE:
return <div>{getDateString(false)}</div>;
break;
case constants.ONLY_TIME:
return <div>{getTimeString(false)}</div>;
break;
default:
return "";
}
};
return (
buildObjectFromDate()
);
};
Según entiendo todo está bien y retorna lo adecuado (string o JSX) pero cuando intento invocarlo así:
<MyDateField date={entity} format={constants.SHORT_DATETIME} />
El navegador devuelve el siguiente error:
React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
MessageTrabajando en React tengo este problema....
14 September 2020Nearby in the feed
Nthis message
C