-
-
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.
Replace connect by hooks in easy components
- Loading branch information
1 parent
9b08ceb
commit 84db55b
Showing
13 changed files
with
138 additions
and
209 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 |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { useSelector } from 'react-redux'; | ||
import { Layout, Sidebar } from 'react-admin'; | ||
import AppBar from './AppBar'; | ||
import Menu from './Menu'; | ||
import { darkTheme, lightTheme } from './themes'; | ||
|
||
const CustomSidebar = props => <Sidebar {...props} size={200} />; | ||
const CustomLayout = props => ( | ||
<Layout {...props} appBar={AppBar} sidebar={CustomSidebar} menu={Menu} /> | ||
); | ||
|
||
export default connect( | ||
state => ({ | ||
theme: state.theme === 'dark' ? darkTheme : lightTheme, | ||
}), | ||
{} | ||
)(CustomLayout); | ||
export default props => { | ||
const theme = useSelector(state => | ||
state.theme === 'dark' ? darkTheme : lightTheme | ||
); | ||
return ( | ||
<Layout | ||
{...props} | ||
appBar={AppBar} | ||
sidebar={CustomSidebar} | ||
menu={Menu} | ||
theme={theme} | ||
/> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,47 +1,41 @@ | ||
import React, { Component } from 'react'; | ||
import React, { useCallback } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { useDispatch } from 'react-redux'; | ||
import NavigationRefresh from '@material-ui/icons/Refresh'; | ||
import { refreshView as refreshViewAction } from 'ra-core'; | ||
import { refreshView } from 'ra-core'; | ||
|
||
import Button from './Button'; | ||
|
||
class RefreshButton extends Component { | ||
static propTypes = { | ||
label: PropTypes.string, | ||
refreshView: PropTypes.func.isRequired, | ||
icon: PropTypes.element, | ||
}; | ||
|
||
static defaultProps = { | ||
label: 'ra.action.refresh', | ||
icon: <NavigationRefresh />, | ||
}; | ||
|
||
handleClick = event => { | ||
const { refreshView, onClick } = this.props; | ||
event.preventDefault(); | ||
refreshView(); | ||
|
||
if (typeof onClick === 'function') { | ||
onClick(); | ||
} | ||
}; | ||
|
||
render() { | ||
const { label, refreshView, icon, ...rest } = this.props; | ||
|
||
return ( | ||
<Button label={label} onClick={this.handleClick} {...rest}> | ||
{icon} | ||
</Button> | ||
); | ||
} | ||
} | ||
|
||
const enhance = connect( | ||
null, | ||
{ refreshView: refreshViewAction } | ||
); | ||
|
||
export default enhance(RefreshButton); | ||
const defaultIcon = <NavigationRefresh />; | ||
|
||
const RefreshButton = ({ | ||
label = 'ra.action.refresh', | ||
icon = defaultIcon, | ||
onClick, | ||
...rest | ||
}) => { | ||
const dispatch = useDispatch(); | ||
const handleClick = useCallback( | ||
event => { | ||
event.preventDefault(); | ||
dispatch(refreshView()); | ||
if (typeof onClick === 'function') { | ||
onClick(); | ||
} | ||
}, | ||
[dispatch, onClick] | ||
); | ||
|
||
return ( | ||
<Button label={label} onClick={handleClick} {...rest}> | ||
{icon} | ||
</Button> | ||
); | ||
}; | ||
|
||
RefreshButton.propTypes = { | ||
label: PropTypes.string, | ||
icon: PropTypes.element, | ||
}; | ||
|
||
export default RefreshButton; |
Oops, something went wrong.