-
-
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 #3225 from marmelab/migrate-example-simple-hooks
[RFR] Migrate simple example to hooks
- Loading branch information
Showing
11 changed files
with
454 additions
and
453 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { useSelector } from 'react-redux'; | ||
import { SimpleShowLayout, TextField } from 'react-admin'; | ||
|
||
const PostPreviewView = ({ isLoading, ...props }) => ( | ||
<SimpleShowLayout {...props}> | ||
<TextField source="id" /> | ||
<TextField source="title" /> | ||
<TextField source="teaser" /> | ||
</SimpleShowLayout> | ||
); | ||
const PostPreview = props => { | ||
const record = useSelector( | ||
state => | ||
state.admin.resources[props.resource] | ||
? state.admin.resources[props.resource].data[props.id] | ||
: null, | ||
[props.resource, props.id], | ||
); | ||
const version = useSelector(state => state.admin.ui.viewVersion); | ||
const isLoading = useSelector(state => state.admin.loading > 0); | ||
|
||
const mapStateToProps = (state, props) => ({ | ||
record: state.admin.resources[props.resource] | ||
? state.admin.resources[props.resource].data[props.id] | ||
: null, | ||
isLoading: state.admin.loading > 0, | ||
version: state.admin.ui.viewVersion, | ||
}); | ||
return ( | ||
<SimpleShowLayout version={version} record={record} {...props}> | ||
<TextField source="id" /> | ||
<TextField source="title" /> | ||
<TextField source="teaser" /> | ||
</SimpleShowLayout> | ||
); | ||
}; | ||
|
||
export default connect( | ||
mapStateToProps, | ||
{} | ||
)(PostPreviewView); | ||
export default PostPreview; |
Oops, something went wrong.