Skip to content

Commit d709b4f

Browse files
add ready function section to readme.md file
1 parent 1c1a44e commit d709b4f

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

README.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ React Dynamic Tabs with full API
3333
- [Syntax](#syntax)
3434
- [Minimal Usage Example](#minimal-usage-example)
3535
- [Simple Manipulation Example](#simple-manipulation-example)
36+
- [ready function](#ready-function)
3637
- [Options](#options)
3738
- [tabs](#tabs)
3839
- [selectedTabID](#selectedtabid)
@@ -167,7 +168,9 @@ const initialOptions = {
167168

168169
export default () => {
169170
const [TabList, PanelList, ready] = useDynTabs(initialOptions);
171+
170172
const addTab3 = function () {
173+
// use ready function to access the instance object
171174
ready((instance) => {
172175
// open tab 3
173176
instance.open({id: '3', title: 'Tab 3', panelComponent: (props) => <p> panel 3 </p>}).then(() => {
@@ -190,21 +193,34 @@ export default () => {
190193
};
191194
```
192195

193-
**NOTE :**
196+
## ready function
194197

195-
- Use `ready` function to access the `instance` object
198+
The `ready` function in the `react-dyn-tabs` library is part of the array returned by the `useDynTabs` hook, alongside the `TabList` and `PanelList` components. This function allows developers to execute a callback once the `TabList` and `PanelList` components are fully mounted, providing access to the instance object for further manipulation.
196199

197-
```js
198-
ready((instance) => {
199-
// manipulate tabs using instance object here
200-
});
201-
```
200+
### Key Features
201+
202+
- **Multiple Calls**: Developers can invoke the `ready` function multiple times without any issues.
203+
- **Stable Identity**: The reference to the `ready` function remains stable across component re-renders, ensuring consistent behavior.
204+
- **Immediate Execution**: If the `ready` function is called after the tabs have already been mounted, the provided callback will be executed immediately.
202205

203-
- `ready` function accepts a `callback` as its parameter and executes it as soon as Tabs get mounted.
206+
### Example Usage
204207

205-
- If `ready` function is called after the Tabs has been mounted, the `callback` passed in will be executed immediately.
208+
```js
209+
const [TabList, PanelList, ready] = useDynTabs(initialOptions);
206210

207-
- `ready` function can be executed multiple times and its identity is stable and won’t change on re-renders.
211+
const addTab3 = function () {
212+
ready((instance) => {
213+
// open tab 3
214+
instance.open({id: '3', title: 'Tab 3', panelComponent: (props) => <p> panel 3 </p>}).then(() => {
215+
console.log('tab 3 is open');
216+
});
217+
// switch to tab 3
218+
instance.select('3').then(() => {
219+
console.log('tab 3 is selected');
220+
});
221+
});
222+
};
223+
```
208224

209225
## Options
210226

0 commit comments

Comments
 (0)