Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Datagrid in dashboard requires resource. #10488

Closed
rayjs opened this issue Feb 1, 2025 · 2 comments · Fixed by #10491
Closed

Using Datagrid in dashboard requires resource. #10488

rayjs opened this issue Feb 1, 2025 · 2 comments · Fixed by #10491

Comments

@rayjs
Copy link

rayjs commented Feb 1, 2025

Hi

Datagrid seems to be looking for resource which isnt available in this sample code.
Code copied from here: https://marmelab.com/react-admin/useList.html

Please see the project here.
https://stackblitz.com/edit/github-8jwzr8vw?file=src%2Findex.tsx,src%2FdashBoard.tsx

I get the following error:
"useCanAccess must be used inside a component or provide a resource prop"

Is this expected behavior. Thank you for your time.

    useList,
    ListContextProvider,
    Datagrid,
    TextField
} from 'react-admin';

const data = [
    { id: 1, name: 'Arnold' },
    { id: 2, name: 'Sylvester' },
    { id: 3, name: 'Jean-Claude' },
];

const MyComponent = () => {
    const listContext = useList({ data });
    return (
        <ListContextProvider value={listContext}>
            <Datagrid>
                <TextField source="id" />
                <TextField source="name" />
            </Datagrid>
        </ListContextProvider>
    );
};

@rayjs rayjs changed the title Using Datagrid in dashboard component requires resource. Using Datagrid in dashboard requires resource. Feb 1, 2025
@rayjs
Copy link
Author

rayjs commented Feb 1, 2025

It works when i provide the resource option.
<Datagrid resource="data">

Unlike whats mentioned here
https://marmelab.com/react-admin/useList.html

@fzaninotto
Copy link
Member

Thanks for the report, it is indeed a documentation problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants