Skip to content
Permalink
Browse files

feat: pick variant before mount to avoid unnecessary render call

  • Loading branch information...
danhayden committed Jul 20, 2017
1 parent 8339664 commit ace02490d43c6409983e5f7f99cae55a8728dc19
Showing with 10 additions and 7 deletions.
  1. +10 −7 src/react-simple-experiment.js
@@ -19,7 +19,7 @@ export class Experiment extends React.Component {

state = {variant: null}

componentDidMount () {
componentWillMount () {
const storageName = `experiment--${this.props.name}`
const variantNames = []
const data = {}
@@ -36,17 +36,20 @@ export class Experiment extends React.Component {
}

this.setState({variant}, () => {
this.props.onLoad(this.props.name, this.state.variant)
this.props.onLoad(this.props.name, variant)
})
})
}

render () {
if (!this.props.children) return null
const variant = this.props.children.find(
child => child.props.name === this.state.variant
)
return variant || null
if (!this.state.variant) {
return null
} else {
const variant = this.props.children.find(
child => child.props.name === this.state.variant
)
return variant || null
}
}
}

0 comments on commit ace0249

Please sign in to comment.
You can’t perform that action at this time.