-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10412 from marmelab/allow-record-override-from-lo…
…cation-everywhere Allow record override from location everywhere
- Loading branch information
Showing
18 changed files
with
611 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
layout: default | ||
title: "The useRecordFromLocation Hook" | ||
--- | ||
|
||
# `useRecordFromLocation` | ||
|
||
Return a record that was passed through either [the location query or the location state](https://reactrouter.com/6.28.0/start/concepts#locations). | ||
|
||
You may use it to know whether the form values of the current create or edit view have been overridden from the location as supported by the [`Create`](./Create.md#prefilling-the-form) and [`Edit`](./Edit.md#prefilling-the-form) components. | ||
|
||
## Usage | ||
|
||
```tsx | ||
// in src/posts/PostEdit.tsx | ||
import * as React from 'react'; | ||
import { Alert } from '@mui/material'; | ||
import { Edit, SimpleForm, TextInput, useRecordFromLocation } from 'react-admin'; | ||
|
||
export const PostEdit = () => { | ||
const recordFromLocation = useRecordFromLocation(); | ||
return ( | ||
<Edit> | ||
{recordFromLocation | ||
? ( | ||
<Alert variant="filled" severity="info"> | ||
The record has been modified. | ||
</Alert> | ||
) | ||
: null | ||
} | ||
<SimpleForm> | ||
<TextInput source="title" /> | ||
</SimpleForm> | ||
</Edit> | ||
); | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
Here are all the options you can set on the `useRecordFromLocation` hook: | ||
|
||
| Prop | Required | Type | Default | Description | | ||
| -------------- | -------- | ---------- | ---------- | -------------------------------------------------------------------------------- | | ||
| `searchSource` | | `string` | `'source'` | The name of the location search parameter that may contains a stringified record | | ||
| `stateSource` | | `string` | `'record'` | The name of the location state parameter that may contains a stringified record | | ||
|
||
## `searchSource` | ||
|
||
The name of the [location search](https://reactrouter.com/6.28.0/start/concepts#locations) parameter that may contains a stringified record. Defaults to `source`. | ||
|
||
## `stateSource` | ||
|
||
The name of the [location state](https://reactrouter.com/6.28.0/start/concepts#locations) parameter that may contains a stringified record. Defaults to `record`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.