I have this es6 + jsx code than work fine:
// list.js
import React from 'react';
import {
List,
Datagrid,
Filter,
TextInput,
NumberField,
TextField,
} from 'admin-on-rest/lib/mui';
const Filters = props =>
<Filter {...props}>
<TextInput source="q" alwaysOn />
</Filter>
;
export default props => (
<List {...props} filters={<Filters />} >
<Datagrid>
<NumberField source="id" />
<TextField source="description" />
</Datagrid>
</List>
);
I want extract Filters definition in a separate source file.
I tried this way:
// filters.js
import React from 'react';
import {
Filter,
TextInput,
TextField,
} from 'admin-on-rest';
export default props =>
<Filter {...props}>
<TextInput source="q" alwaysOn />
</Filter>
;
and
// list.js
import React from 'react';
import {
List,
Datagrid,
Filter,
TextInput,
NumberField,
TextField,
} from 'admin-on-rest/lib/mui';
import Filters from 'filters';
export default props => (
<List {...props} filters={<Filters />} >
<Datagrid>
<NumberField source="id" />
<TextField source="description" />
</Datagrid>
</List>
);
I thought the code was equivalent, but in the second case I get a couple of
Warning: 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.
and finally this error
Uncaught (in promise) Error: Element 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. Check the render method of
StatelessComponent
.
The major indicted is
filters={<Filters />}
but what would be the correct syntax?