Created
February 9, 2019 13:24
-
-
Save hckhanh/5a09758ac204611349b53bc3b959ca9c to your computer and use it in GitHub Desktop.
Need manage editMode state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PropTypes from 'prop-types'; | |
import React, { Component, Fragment } from 'react'; | |
import EditModeItem from './EditModeItem'; | |
import './style.scss'; | |
import ViewModeItem from './ViewModeItem'; | |
export default class EditableItem extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { editMode: false }; | |
} | |
render() { | |
return ( | |
<Fragment> | |
{this.state.editMode ? ( | |
<EditModeItem | |
data={this.props.data} | |
onCancel={() => this.setState({ editMode: false })} | |
/> | |
) : ( | |
<ViewModeItem | |
data={this.props.data} | |
onEdit={() => this.setState({ editMode: true })} | |
/> | |
)} | |
<div className="editable-item-divider" /> | |
</Fragment> | |
); | |
} | |
} | |
EditableItem.propTypes = { | |
data: PropTypes.object.isRequired | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment