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

Aside does not seem to have access to record. #2511

Closed
szi opened this issue Nov 7, 2018 · 4 comments
Closed

Aside does not seem to have access to record. #2511

szi opened this issue Nov 7, 2018 · 4 comments
Assignees
Labels

Comments

@szi
Copy link

szi commented Nov 7, 2018

What you were expecting:
According to the documentation, I should be able to access the record's property within the <Aside> consctruct. However, it tells me that record is undefined.

In my case, I am using Aside within the Edit view.

Steps to reproduce:
My Aside sample code is pretty much just copied from the react-admin documentation:

const FilterQueryAside = ({ record }) => (
  <div style={{ width: 200, margin: '1em' }}>
       <Typography variant="title">Post details</Typography>
       <Typography variant="body1">
           Creation date: {record.id}
       </Typography>
   </div>
);

export const FilterQueryEdit = (props) => (
  <Edit aside={<FilterQueryAside />} title="Edit Filter Query" {...props}>
  <SimpleForm redirect="edit">
...

I get a "TypeError: Cannot read property 'id' of undefined"

Do I have to manually pass the record into the Aside?

Finally, would it be possible to use react-admin Fields within the aside? How could I achieve that?

Environment

  • React-admin version: 2.4.1
  • Last version that did not exhibit the issue (if applicable):
  • React version:16.6.1
  • Browser: Chrome V68
  • Stack trace (in case of a JS error):
@szi
Copy link
Author

szi commented Nov 7, 2018

Quick update on this: It happens only sometimes.

When I click on a post from the list view, it loads fine and shows the Aside. When I then click browser's refresh, I get the error of record being undefined. It seems like the Aside does not wait properly for the record to actually be loaded before being rendered.

Just confirmed the hypothesis: it does throw the "record is undefined" before any REST API query ever gets sent across the network, so there definitely is no record to even work with.

@fzaninotto
Copy link
Member

No react-admin component waits for the record to be loaded to render - that's one of many optimizations that we do to display the UI quickly. It's the developper's job to make sure that the record is defined before using it.

@szi
Copy link
Author

szi commented Nov 7, 2018

Ok, thanks.
I would suggest an update to the sample code in the documentation then, as the current version is not functional.

Is there a suggested way to use pre-existing react-admin components within Aside? Such as TextField etc? Would I need to wrap those in something?

@fzaninotto
Copy link
Member

You're right, it's a documentation problem. Reopening and marking as bug.

As for your question, please use StackOverflow.

@fzaninotto fzaninotto reopened this Nov 8, 2018
@fzaninotto fzaninotto added the bug label Nov 8, 2018
@fzaninotto fzaninotto self-assigned this Nov 8, 2018
fzaninotto added a commit that referenced this issue Nov 8, 2018
@djhi djhi closed this as completed in #2513 Nov 8, 2018
mikaoelitiana pushed a commit to mikaoelitiana/react-admin that referenced this issue Nov 22, 2018
mikaoelitiana pushed a commit to mikaoelitiana/react-admin that referenced this issue Nov 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants