Skip to content

Commit

Permalink
docs: examples not fully shown until first state change (#1065)
Browse files Browse the repository at this point in the history
  • Loading branch information
Georift authored and jquense committed Nov 7, 2018
1 parent fef6f9d commit 6c6efb3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions examples/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,26 @@ const EXAMPLES = {
dnd: 'Addon: Drag and drop',
}

const DEFAULT_EXAMPLE = 'basic'

class Example extends React.Component {
constructor(...args) {
super(...args)

const hash = (window.location.hash || '').slice(1)

this.state = {
selected: EXAMPLES[hash] ? hash : 'basic',
selected: DEFAULT_EXAMPLE,
}
}

select = selected => {
this.setState({ selected })
}

componentDidMount() {
const hash = (window.location.hash || '').slice(1)
this.select(hash || DEFAULT_EXAMPLE)
}

render() {
let selected = this.state.selected
let Current = {
Expand Down Expand Up @@ -126,6 +132,7 @@ class Example extends React.Component {
<Dropdown.Menu>
{Object.entries(EXAMPLES).map(([key, title]) => (
<MenuItem
active={this.state.selected === key}
key={key}
href={`#${key}`}
onClick={() => this.select(key)}
Expand Down

0 comments on commit 6c6efb3

Please sign in to comment.