-
Notifications
You must be signed in to change notification settings - Fork 5
Switcher #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Switcher #42
Conversation
| import React, { PropTypes } from 'react'; | ||
|
|
||
| export default class Switcher extends React.Component { | ||
| static propTypes = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
даваем ему сделаем внутреннее состояние isChecked и надо не забыть про componentWillReceiveProps
src/Switcher/Switcher.jsx
Outdated
| } | ||
| } | ||
|
|
||
| const styles = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Надо переслать на StyleSheet.create({})
| import StateProvider from '../StateProvider'; | ||
|
|
||
| storiesOf('Switcher', module) | ||
| .add('Switcher', () => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
добавить кейс где он без внешнего состояния переключается
| import React, { PropTypes } from 'react'; | ||
|
|
||
| export default class Switcher extends React.Component { | ||
| static propTypes = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
давай добавил onChange и isDisabled
src/Switcher/Switcher.jsx
Outdated
|
|
||
| this.state = { | ||
| isChecked: props.isChecked, | ||
| isDisabled: props.isDisabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isDisabled не надо держать в стейте, достаточно получения через props
| this._onClickHandler = this._onClickHandler.bind(this); | ||
| this._onChangeHandler = this._onChangeHandler.bind(this); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нужно добавить обновление стейта на componentWillReceiveProps
src/Switcher/Switcher.jsx
Outdated
|
|
||
| getDefaultRenderProps() { | ||
| return { | ||
| onChange: this._onChangeHandler, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onChange не нужен
src/Switcher/Switcher.jsx
Outdated
| getDefaultRenderProps() { | ||
| return { | ||
| onChange: this._onChangeHandler, | ||
| onClick: this._onClickHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onClick можно сразу в rendere навесить
src/Switcher/Switcher.jsx
Outdated
| const props = this.props; | ||
|
|
||
| if (!props.isDisabled) { | ||
| this.setState({ isChecked: !this.state.isChecked }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.setState({ isChecked: !this.state.isChecked }, () => {
props.onClick && props.onClick(event);
props.onChange && props.onChange(this.state.isChecked);
})
No description provided.