dsuryd / dotNetify

Simple, lightweight, yet powerful way to build real-time web apps.
https://dotnetify.net
Other
1.17k stars 164 forks source link

can't load styled material-ui view #245

Closed Spongman closed 4 years ago

Spongman commented 4 years ago

i'm getting an error in dotnetify-react.js (in loadReactView()):

dotnetify-react.js:3766 [AppLayout] failed to load view '[object Object]' because it's not a valid React element.

the component is defined as a styled material-ui component somewhat like this:

const styles = (theme: Theme) => createStyles({
    ...
});
interface Props extends WithStyles<typeof styles> {
    ...
};
class MyComponentClass extends React.Component<Props> {
    ...
};
export const MyComponent = withStyles(styles)(MyComponentClass);

the check that's failing is:

if (typeof iComponent !== 'function' && ((typeof iComponent === 'undefined' ? 'undefined' : _typeof(iComponent)) !== 'object' || iComponent.name == null)) {

typeof iComponent is "object"

dsuryd commented 4 years ago

The check incorrectly expects a React component to always have a name property. For now, the workaround is to add it manually:

export const MyComponent = Object.assign(withStyles(styles)(MyComponentClass), { name: '' });