Skip to content

Conversation

@Kanonir87
Copy link
Contributor

No description provided.

import React, { PropTypes } from 'react';

export default class Switcher extends React.Component {
static propTypes = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

даваем ему сделаем внутреннее состояние isChecked и надо не забыть про componentWillReceiveProps

}
}

const styles = {
Copy link
Contributor

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', () => (
Copy link
Contributor

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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай добавил onChange и isDisabled


this.state = {
isChecked: props.isChecked,
isDisabled: props.isDisabled
Copy link
Contributor

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);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно добавить обновление стейта на componentWillReceiveProps


getDefaultRenderProps() {
return {
onChange: this._onChangeHandler,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onChange не нужен

getDefaultRenderProps() {
return {
onChange: this._onChangeHandler,
onClick: this._onClickHandler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onClick можно сразу в rendere навесить

const props = this.props;

if (!props.isDisabled) {
this.setState({ isChecked: !this.state.isChecked });
Copy link
Contributor

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);
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants