Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Elem = (props) =>{
- return (<div>
- <h1 onClick={props.clickon} id="GM"> Good Morning!
- <br/>
- {props.name} {props.last}
- <br />
- This is phase three</h1>
- <button id="btn1" onClick={props.clickon}> {props.text} </button>
- <button id="btn2" onClick={props.clickon}> Second Button </button>
- </div>
- );
- };
- class App extends React.Component{
- constructor(props) {
- super(props);
- this.handleClick = this.handleClick.bind(this);
- }
- handleClick(){
- var clickedId = event.target.id;
- console.log(clickedId);
- alert("It works! You clicked " + clickedId)
- }
- render(){
- return (
- <Elem name = 'paul' last='shreeman' clickon={this.handleClick} text='PushMe'/>
- )
- }
- }
- ReactDOM.render(
- <App />, document.getElementById('root'))
- handleClick(event) {
- var clickedId = event.target.id;
- console.log(clickedId);
- alert("It works! You clicked " + clickedId)
- }
- const Elem = (props) =>{
- return (<div>
- <h1 onClick={props.clickon} id="GM"> Good Morning!
- <br/>
- {props.name} {props.last}
- <br />
- This is phase three</h1>
- <button id="btn1" onClick={props.clickon}> {props.text} </button>
- <button id="btn2" onClick={props.clickon}> Second Button </button>
- </div>
- );
- };
- class App extends React.Component{
- constructor(props) {
- super(props);
- this.handleClick = this.handleClick.bind(this);
- }
- handleClick(event){
- var clickedId = event.target.id;
- console.log(clickedId);
- alert("It works! You clicked " + clickedId)
- }
- render(){
- return (
- <Elem name = 'paul' last='shreeman' clickon={(event)=>this.handleClick(event)} text='PushMe'/>
- )
- }
- }
- ReactDOM.render(
- <App />, document.getElementById('root'))
Add Comment
Please, Sign In to add comment