Skip to content

Commit 17eb8e9

Browse files
committed
feat: initial number of render items
1 parent d68b530 commit 17eb8e9

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ const data = [{title: 'Node 1', items: [{title: 'Node 1.1'}, {title: 'Node 1.2'}
5252

5353
### NestedListView
5454

55-
| Prop | Description | Type | Default |
56-
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------------ |
57-
| **`data`** | Array of nested items | Array | **Required** |
58-
| **`renderNode`** | Takes a node from data and renders it into the NestedlistView. The function receives `{node, level, isLastLevel}` (see [Usage](#usage)) and must return a React element. | Function | **Required** |
59-
| **`getChildrenName`** | Function to determine in a node where are the children, by default NestedListView will try to find them in **items** | Function | **items** |
60-
| **`onNodePressed`** | Function called when a node is pressed by a user | Function | Not required |
61-
| **`extraData`** | A marker property for telling the list to re-render | Boolean | Not required |
62-
| **`keepOpenedState`** | Prop for keeping the opened state of each node when data passed to the list changes | Boolean | Not required |
55+
| Prop | Description | Type | Default |
56+
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------------ |
57+
| **`data`** | Array of nested items | Array | **Required** |
58+
| **`renderNode`** | Takes a node from data and renders it into the NestedlistView. The function receives `{node, level, isLastLevel}` (see [Usage](#usage)) and must return a React element. | Function | **Required** |
59+
| **`getChildrenName`** | Function to determine in a node where are the children, by default NestedListView will try to find them in **items** | Function | **items** |
60+
| **`onNodePressed`** | Function called when a node is pressed by a user | Function | Not required |
61+
| **`extraData`** | A marker property for telling the list to re-render | Boolean | Not required |
62+
| **`keepOpenedState`** | Prop for keeping the opened state of each node when data passed to the list changes | Boolean | Not required |
63+
| **`initialNumToRender`** | Prop for setting the initial amount of items to render. | number | Not required |
6364

6465
### NestedRow
6566

@@ -111,7 +112,7 @@ When you finish with watch mode remember to stop it to get back to normal like t
111112

112113
## Invite me a coffee
113114

114-
If you want to invite me for a coffee after enjoying this library or just for fun.
115+
If you want to invite me for a coffee after enjoying this library or just for fun.
115116

116117
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/D1D16TF2V)
117118

src/nested-list-view/nested-list-view.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface IProps {
3232
getChildrenName?: (item: INode) => string;
3333
style?: StyleSheet;
3434
keepOpenedState?: boolean;
35+
initialNumToRender?: number;
3536
}
3637

3738
const DEFAULT_CHILDREN_NAME = 'items';
@@ -52,6 +53,7 @@ const NestedListView: React.FC<IProps> = React.memo(
5253
onNodePressed,
5354
extraData,
5455
keepOpenedState,
56+
initialNumToRender,
5557
}: IProps) => {
5658
const generateIds = useCallback(
5759
(node?: INode) => {
@@ -165,6 +167,7 @@ const NestedListView: React.FC<IProps> = React.memo(
165167
renderNode={renderNode}
166168
extraData={extraData}
167169
keepOpenedState={keepOpenedState}
170+
initialNumToRender={initialNumToRender}
168171
/>
169172
</NodeProvider>
170173
);

src/node-view/node-view.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface IProps {
1616
renderChildrenNode?: (item: INode) => ReactElement;
1717
extraData?: any;
1818
keepOpenedState?: boolean;
19+
initialNumToRender?: number;
1920
}
2021

2122
const NodeView: React.FC<IProps> = React.memo(
@@ -27,6 +28,7 @@ const NodeView: React.FC<IProps> = React.memo(
2728
node,
2829
onNodePressed,
2930
keepOpenedState,
31+
initialNumToRender,
3032
}) => {
3133
const { openedNodes, setOpenNode } = useNodesContext();
3234

@@ -105,6 +107,7 @@ const NodeView: React.FC<IProps> = React.memo(
105107
extraData={extraData}
106108
keyExtractor={keyExtractor}
107109
listKey={node._internalId}
110+
initialNumToRender={initialNumToRender}
108111
/>
109112
) : null}
110113
</>

0 commit comments

Comments
 (0)