Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Cleanup unnecessary usages of compose() #6001

Merged
merged 4 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,25 @@ From React's documentation -
>Props and composition give you all the flexibility you need to customize a component’s look and behavior in an explicit and safe way. Remember that components may accept arbitrary props, including primitive values, React elements, or functions.
>If you want to reuse non-UI functionality between components, we suggest extracting it into a separate JavaScript module. The components may import it and use that function, object, or a class, without extending it.

Use *[Higher order components](https://reactjs.org/docs/higher-order-components.html)* if you find a use case where you need inheritance.
Use an HOC a.k.a. *[Higher order component](https://reactjs.org/docs/higher-order-components.html)* if you find a use case where you need inheritance.

If several HOC need to be combined there is a `compose()` utility. But we should not use this utility when there is only one HOC.

```javascript
// Bad
export default compose(
withLocalize,
)(MyComponent);

// Good
export default compose(
withLocalize,
withWindowDimensions,
)(MyComponent);

// Good
export default withLocalize(MyComponent)
```

**Note:** If you find that none of these approaches work for you, please ask an Expensify engineer for guidance via Slack or GitHub.

Expand Down
3 changes: 1 addition & 2 deletions src/components/HeaderWithCloseButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import styles from '../styles/styles';
import Header from './Header';
import Icon from './Icon';
import {Close, Download, BackArrow} from './Icon/Expensicons';
import compose from '../libs/compose';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import Tooltip from './Tooltip';
import InboxCallButton from './InboxCallButton';
Expand Down Expand Up @@ -123,4 +122,4 @@ HeaderWithCloseButton.propTypes = propTypes;
HeaderWithCloseButton.defaultProps = defaultProps;
HeaderWithCloseButton.displayName = 'HeaderWithCloseButton';

export default compose(withLocalize)(HeaderWithCloseButton);
export default withLocalize(HeaderWithCloseButton);
5 changes: 1 addition & 4 deletions src/components/ImageView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
import styles, {getZoomCursorStyle, getZoomSizingStyle} from '../../styles/styles';
import canUseTouchScreen from '../../libs/canUseTouchscreen';
import withWindowDimensions, {windowDimensionsPropTypes} from '../withWindowDimensions';
import compose from '../../libs/compose';

const propTypes = {
/** URL to full-sized image */
Expand Down Expand Up @@ -223,6 +222,4 @@ class ImageView extends PureComponent {
}

ImageView.propTypes = propTypes;
export default compose(
withWindowDimensions,
)(ImageView);
export default withWindowDimensions(ImageView);
3 changes: 1 addition & 2 deletions src/components/InboxCallButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import styles from '../styles/styles';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import compose from '../libs/compose';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import Tooltip from './Tooltip';
Expand Down Expand Up @@ -39,4 +38,4 @@ const InboxCallButton = props => (
InboxCallButton.propTypes = propTypes;
InboxCallButton.defaultProps = defaultProps;
InboxCallButton.displayName = 'InboxCallButton';
export default compose(withLocalize)(InboxCallButton);
export default withLocalize(InboxCallButton);
19 changes: 8 additions & 11 deletions src/pages/LogInWithShortLivedTokenPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import ROUTES from '../ROUTES';
import compose from '../libs/compose';
import ONYXKEYS from '../ONYXKEYS';
import {signInWithShortLivedToken} from '../libs/actions/Session';
import FullScreenLoadingIndicator from '../components/FullscreenLoadingIndicator';
Expand Down Expand Up @@ -98,13 +97,11 @@ class LogInWithShortLivedTokenPage extends Component {
LogInWithShortLivedTokenPage.propTypes = propTypes;
LogInWithShortLivedTokenPage.defaultProps = defaultProps;

export default compose(
withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
betas: {
key: ONYXKEYS.BETAS,
},
}),
)(LogInWithShortLivedTokenPage);
export default withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
betas: {
key: ONYXKEYS.BETAS,
},
})(LogInWithShortLivedTokenPage);
8 changes: 1 addition & 7 deletions src/pages/settings/Payments/AddDebitCardPage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, {Component} from 'react';
import {withOnyx} from 'react-native-onyx';
import {
View,
ScrollView,
Expand All @@ -13,7 +12,6 @@ import StatePicker from '../../../components/StatePicker';
import Text from '../../../components/Text';
import TextLink from '../../../components/TextLink';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import compose from '../../../libs/compose';
import {addBillingCard} from '../../../libs/actions/PaymentMethods';
import Button from '../../../components/Button';
import KeyboardAvoidingView from '../../../components/KeyboardAvoidingView';
Expand Down Expand Up @@ -241,8 +239,4 @@ DebitCardPage.propTypes = propTypes;
DebitCardPage.defaultProps = defaultProps;
DebitCardPage.displayName = 'DebitCardPage';

export default compose(
withLocalize,
withOnyx({
}),
)(DebitCardPage);
export default withLocalize(DebitCardPage);