Skip to content

Instantly share code, notes, and snippets.

@hashirahmad
Created January 6, 2019 20:02
Show Gist options
  • Save hashirahmad/c78445b0ca1c430596e2e161abed252b to your computer and use it in GitHub Desktop.
Save hashirahmad/c78445b0ca1c430596e2e161abed252b to your computer and use it in GitHub Desktop.
ReactExampleUsable.js
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