Created
January 6, 2019 20:02
-
-
Save hashirahmad/c78445b0ca1c430596e2e161abed252b to your computer and use it in GitHub Desktop.
ReactExampleUsable.js
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 React, {Component} from 'react'; | |
import PropTypes from 'prop-types'; | |
class Test extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
name:'Hashir', | |
age:20 | |
} | |
} | |
edit() { | |
//submit to server or whatever | |
} | |
render() { | |
const noedit = ( | |
return <p>You cannot edit this</p> | |
) | |
const edit = ( | |
return <div> | |
<p>You can edit this</p> | |
<input onChange={() => { | |
this.setState({ | |
name: e.target.value | |
}) | |
}} | |
<input onChange={() => { | |
this.setState({ | |
age: e.target.value | |
}) | |
}} | |
<button onPress={this.edit}></button> | |
</div> | |
) | |
return ( | |
<div> | |
{!this.props.edit ? noedit : edit} | |
</div> | |
); | |
} | |
} | |
Test.propTypes = {}; | |
export default Test; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment