Skip to content

Commit

Permalink
doc(readme): refactor controlled components to hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Ferreira authored and danez committed Aug 20, 2020
1 parent c89e2c0 commit 095777b
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,24 +274,20 @@ In this mode react-tabs does not handle any tab selection state internally and l
This mode also enforces you to set a handler for `onSelect`. `defaultIndex` does not have any effect and will therefore throw an error.
```js
class App extends Component {
constructor() {
super();
this.state = { tabIndex: 0 };
}
render() {
return (
<Tabs selectedIndex={this.state.tabIndex} onSelect={tabIndex => this.setState({ tabIndex })}>
<TabList>
<Tab>Title 1</Tab>
<Tab>Title 2</Tab>
</TabList>
<TabPanel></TabPanel>
<TabPanel></TabPanel>
</Tabs>
);
}
}
const App = () => {
const [tabIndex, setTabIndex] = useState(0);
return (
<Tabs selectedIndex={tabIndex} onSelect={index => setTabIndex(index)}>
<TabList>
<Tab>Title 1</Tab>
<Tab>Title 2</Tab>
</TabList>
<TabPanel></TabPanel>
<TabPanel></TabPanel>
</Tabs>
);
};
```
## Styling
Expand Down

0 comments on commit 095777b

Please sign in to comment.