Skip to content

Commit 7a4b2f7

Browse files
add changeLog.md and update readme
1 parent 4ceb03f commit 7a4b2f7

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# v3.0.0
2+
3+
* useDynTabs hook returns ready function instead of instance object, as a third element of an array.
4+
( tabs can't be manipulated safely before the first render, use ready() to make a function available after the component is mounted )
5+
6+
* Third element of returned array by useDynTabs hook should not be used as an object, it is no longer recommended and only be kept for backwards compatibility purposes, may be removed in the future. Avoid using it as an object.
7+
8+
# v2.2.0
9+
10+
* close function can take switching parameter
11+
12+
# v2.1.0
13+
14+
* panel component option can be either of React element or React component

README.md

+37-7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ React Dynamic Tabs with full API
5959
- [Lazy Loading](#lazy-loading)
6060
- [Styling](#styling)
6161
- [Caveats](#caveats)
62+
- [Deprecated features](#Deprecated-features)
6263
- [Test](#test)
6364
- [License](#license)
6465

@@ -82,7 +83,7 @@ $ yarn add react-dyn-tabs
8283
## Basic Example
8384

8485
```js
85-
import React from 'react';
86+
import React, { useEffect } from 'react';
8687
import useDynTabs from 'react-dyn-tabs';
8788
import 'react-dyn-tabs/style/react-dyn-tabs.css';
8889
import 'react-dyn-tabs/themes/default.css';
@@ -104,11 +105,18 @@ export default () => {
104105
}
105106
],
106107
selectedTabID: '1',
107-
onLoad: function(){
108-
// do sth here
109-
}
108+
onLoad: function () { }
110109
};
111-
const [TabList, PanelList, instance] = useDynTabs(options);
110+
const [TabList, PanelList, ready] = useDynTabs(options);
111+
useEffect(() => {
112+
ready(instance => {
113+
// open more tabs
114+
instance.open({ id: '3', title: 'Tab 3', panelComponent: porps => <p> Tab 3 content </p> });
115+
instance.open({ id: '4', title: 'Tab 4', panelComponent: porps => <p> Tab 4 content </p> });
116+
// switch to new tab
117+
instance.select('4');
118+
});
119+
}, []);
112120
return (
113121
<div>
114122
<TabList></TabList>
@@ -121,8 +129,13 @@ export default () => {
121129

122130
**NOTE :**
123131

124-
instance Object will not be changed after re-rendering multiple times.
125-
Its value always refers to same reference.
132+
* ready function and instance Object will not be changed after re-rendering multiple times.
133+
134+
* Tabs can't be manipulated safely before the first render, use ready() to make a function available after the component is mounted.
135+
136+
* ready function accepts a function as a parameter and calls it with instance object after the first render, when the component is mounted.
137+
138+
* When ready function is called after the first render, it calls its function parameter with instance object immediately.
126139

127140

128141

@@ -1011,6 +1024,23 @@ Some actions like open, select, close and refresh cause re-rendering,
10111024
and using them immediately after calling useDynTabs hook will create an infinite loop and other bugs that most likely you don't want to cause.
10121025
you should use them inside event listeners or subscriptions.
10131026

1027+
## Deprecated features
1028+
1029+
These deprecated features can still be used, but should be used with caution because they are expected to be removed entirely sometime in the future. You should work to remove their use from your code.
1030+
1031+
* Third element of returned array by useDynTabs hook should not be used as an object, it is no longer recommended and only be kept for backwards compatibility purposes, may be removed in the future. Avoid using it as an object and use the code below instead of it.
1032+
1033+
```js
1034+
const [TabList, PanelList, ready] = useDynTabs(options);
1035+
const open_tab_3 = function () {
1036+
ready(function (instance) {
1037+
if (instance.isOpen('3') === false) {
1038+
instance.open({ id: '3', title: 'mock tab 3' });
1039+
instance.select('3');
1040+
}
1041+
});
1042+
};
1043+
```
10141044

10151045
## Test
10161046

0 commit comments

Comments
 (0)