diff --git a/docs/CreateEdit.md b/docs/CreateEdit.md index c39140e9249..eb06fd29850 100644 --- a/docs/CreateEdit.md +++ b/docs/CreateEdit.md @@ -326,7 +326,7 @@ export default PostList = props => ( **Tip**: To style the button with the main color from the material-ui theme, use the `Link` component from the `react-admin` package rather than the one from `react-router-dom`. -**Tip**: The `` component also watches the `location.search` (the query string in the URL) in addition to `location.state` (a cross-page message hidden in the router memory). So the `CreateRelatedCommentButton` could, in theory, be written as: +**Tip**: The `` component also watches the "source" parameter of `location.search` (the query string in the URL) in addition to `location.state` (a cross-page message hidden in the router memory). So the `CreateRelatedCommentButton` could also be written as: {% raw %} ```jsx @@ -339,7 +339,7 @@ const CreateRelatedCommentButton = ({ record }) => ( component={Link} to={{ pathname: '/comments/create', - search: '?post_id=' + record.id, + search: `?source=${JSON.stringify({ post_id: record.id })}`, }} > Write a comment for that post @@ -348,10 +348,6 @@ const CreateRelatedCommentButton = ({ record }) => ( ``` {% endraw %} -However, this will only work if the post ids are typed as strings in the store. That's because the query string `?post_id=123`, once deserialized, reads as `{ post_id: '123' }` and not `{ post_id: 123 }`. Since [the `` uses strict equality to check the selected option](https://github.com/mui-org/material-ui/issues/12047) comparing the `post_id` `'123'` from the URL with values like `123` in the choices will fail. - -So prefer `location.state` instead of `location.search` when you can, or use custom selection components. - ## The `` component Instead of a custom `Edit`, you can use the `EditGuesser` to determine which inputs to use based on the data returned by the API.