-
-
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 #8964 from marmelab/FunctionField-TS-regression
[TypeScript] Fix regression in type of `<FunctionField>` `render`
- Loading branch information
Showing
2 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
packages/ra-ui-materialui/src/field/FunctionField.stories.tsx
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,40 @@ | ||
import * as React from 'react'; | ||
|
||
import { RecordContextProvider } from 'ra-core'; | ||
import { FunctionField } from './FunctionField'; | ||
|
||
export default { title: 'ra-ui-materialui/fields/FunctionField' }; | ||
|
||
export const Basic = () => ( | ||
<RecordContextProvider value={{ firstName: 'John', lastName: 'Doe' }}> | ||
<FunctionField | ||
render={record => `${record.firstName} ${record.lastName}`} | ||
/> | ||
</RecordContextProvider> | ||
); | ||
|
||
type User = { | ||
id: number; | ||
firstName: string; | ||
lastName: string; | ||
}; | ||
|
||
export const Typed = () => ( | ||
<RecordContextProvider<User> | ||
value={{ id: 123, firstName: 'John', lastName: 'Doe' }} | ||
> | ||
<FunctionField<User> | ||
render={record => `${record?.firstName} ${record?.lastName}`} | ||
/> | ||
</RecordContextProvider> | ||
); | ||
|
||
export const NonRegression = () => ( | ||
<RecordContextProvider value={{ firstName: 'John', lastName: 'Doe' }}> | ||
<FunctionField | ||
render={(record?: User) => | ||
`${record?.firstName} ${record?.lastName}` | ||
} | ||
/> | ||
</RecordContextProvider> | ||
); |
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