Skip to content
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
38 changes: 0 additions & 38 deletions contributingGuides/STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1190,44 +1190,6 @@ Use hooks whenever possible, avoid using HOCs.

> Why? Hooks are easier to use (can be used inside the function component), and don't need nesting or `compose` when exporting the component. It also allows us to remove `compose` completely in some components since it has been bringing up some issues with TypeScript. Read the [`compose` usage](#compose-usage) section for further information about the TypeScript issues with `compose`.

Onyx provides a `useOnyx` hook that should be used over the deprecated `withOnyx` HOC.

```tsx
// BAD
type ComponentOnyxProps = {
session: OnyxEntry<Session>;
};

type ComponentProps = ComponentOnyxProps & {
someProp: string;
};

function Component({session, someProp}: ComponentProps) {
const {windowWidth, windowHeight} = useWindowDimensions();
const {translate} = useLocalize();
// component's code
}

export default withOnyx<ComponentProps, ComponentOnyxProps>({
session: {
key: ONYXKEYS.SESSION,
},
})(Component);

// GOOD
type ComponentProps = {
someProp: string;
};

function Component({someProp}: ComponentProps) {
const [session] = useOnyx(ONYXKEYS.SESSION)

const {windowWidth, windowHeight} = useWindowDimensions();
const {translate} = useLocalize();
// component's code
}
```

### Stateless components vs Pure Components vs Class based components vs Render Props - When to use what?

Class components are DEPRECATED. Use function components and React hooks.
Expand Down
7 changes: 1 addition & 6 deletions contributingGuides/philosophies/ONYX-DATA-MANAGEMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ Onyx.init({
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});

export default withOnyx({
reportActions: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
canEvict: props => !props.isActiveReport,
},
})(ReportActionsView);
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, {canEvict: !isActiveReport});
```

## Onyx Derived Values
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"react-native-localize": "^2.2.6",
"react-native-nitro-modules": "0.29.4",
"react-native-nitro-sqlite": "9.1.11",
"react-native-onyx": "2.0.138",
"react-native-onyx": "3.0.1",
"react-native-pager-view": "6.5.3",
"react-native-pdf": "6.7.3",
"react-native-performance": "^5.1.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type TransactionItemRowRBRProps = {
missingFieldError?: string;
};

function TransactionItemRowRBRWithOnyx({transaction, violations, report, containerStyles, missingFieldError}: TransactionItemRowRBRProps) {
function TransactionItemRowRBR({transaction, violations, report, containerStyles, missingFieldError}: TransactionItemRowRBRProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const theme = useTheme();
Expand All @@ -59,7 +59,7 @@ function TransactionItemRowRBRWithOnyx({transaction, violations, report, contain
RBRMessages.length > 0 && (
<View
style={[styles.flexRow, styles.alignItemsCenter, styles.gap1, containerStyles]}
testID="TransactionItemRowRBRWithOnyx"
testID="TransactionItemRowRBR"
>
<Icon
src={DotIndicator}
Expand All @@ -75,5 +75,5 @@ function TransactionItemRowRBRWithOnyx({transaction, violations, report, contain
);
}

TransactionItemRowRBRWithOnyx.displayName = 'TransactionItemRowRBRWithOnyx';
export default TransactionItemRowRBRWithOnyx;
TransactionItemRowRBR.displayName = 'TransactionItemRowRBR';
export default TransactionItemRowRBR;
6 changes: 3 additions & 3 deletions src/components/TransactionItemRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import TagCell from './DataCells/TagCell';
import TaxCell from './DataCells/TaxCell';
import TotalCell from './DataCells/TotalCell';
import TypeCell from './DataCells/TypeCell';
import TransactionItemRowRBRWithOnyx from './TransactionItemRowRBRWithOnyx';
import TransactionItemRowRBR from './TransactionItemRowRBR';

type ColumnComponents = {
[key in ValueOf<typeof CONST.REPORT.TRANSACTION_LIST.COLUMNS>]: React.ReactElement;
Expand Down Expand Up @@ -484,7 +484,7 @@ function TransactionItemRow({
</View>
)}
{shouldShowErrors && (
<TransactionItemRowRBRWithOnyx
<TransactionItemRowRBR
transaction={transactionItem}
violations={violations}
report={report}
Expand Down Expand Up @@ -534,7 +534,7 @@ function TransactionItemRow({
)}
</View>
{shouldShowErrors && (
<TransactionItemRowRBRWithOnyx
<TransactionItemRowRBR
transaction={transactionItem}
violations={violations}
report={report}
Expand Down
Loading