adminjs icon indicating copy to clipboard operation
adminjs copied to clipboard

Cannot pass props to custom Dashboard component

Open Asher-JH opened this issue 3 years ago • 2 comments

Describe the bug Unable to access data passed to custom Dashboard component. Props passed to the custom component is an empty object.

Installed libraries and their versions

To Reproduce Steps to reproduce the behaviour:

  1. Create a React component and inside the component add a console.log(props)
  2. Add the configuration to AdminJS options like below: Screenshot 2022-05-03 at 6 14 17 PM

Expected behaviour Custom Dashboard component rendered & props passed in from handler we provided in configs

Desktop (please complete the following information if relevant):

  • OS: MACOS
  • Browser [chrome]

Additional context The rendering of the Dashboard component is working fine, only problem is no props is being passed in.

  • Docs I referred to do not specify a specific return object for the dashboard handler ( Please correct I'm wrong )

    • https://docs.adminjs.co/tutorial-custom-dashboard.html
    • https://docs.adminjs.co/AdminJSOptions.html#PageHandler
  • The example i referred to for passing data to the component

    • https://github.com/RafaelGoulartB/adminbro-dashboard/blob/main/src/adminbro-options.ts#:~:text=%7D%2C-,dashboard%3A%20%7B,%7D%2C,-rootPath%3A%20%27/admin%27

Screenshot 2022-05-03 at 6 20 03 PM

Asher-JH avatar May 03 '22 10:05 Asher-JH

I'm not sure if this is the way to do it, since the docs (correct me If I'm wrong) don't show exactly how we get the data returned in the handler as props in our custom Dashboard component.

  1. Pass ur handler action in and return the data you need.
  2. Use ApiClient from 'adminjs'
  3. Manually call the handler from your component and store in useState

Screenshot 2022-05-04 at 11 40 09 AM

This is what works for me, though I would prefer to get data as props rather than manually call the handler

Asher-JH avatar May 04 '22 03:05 Asher-JH

The ApiClient approach has to stay in case the content is supposed to stay dynamic. We can consider pre-fetching the data for initial rendering though.

dziraf avatar May 05 '22 09:05 dziraf