Skip to content

Commit 6c86395

Browse files
committed
clickable class component
1 parent baf1ced commit 6c86395

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
3+
class Clickable extends React.Component {
4+
5+
constructor(props) {
6+
super(props);
7+
this.handleClick = this.handleClick.bind(this);
8+
}
9+
10+
handleClick(event) {
11+
console.log(event);
12+
console.log("I was clicked");
13+
}
14+
15+
render() {
16+
return (
17+
<button onClick={this.handleClick}>{this.props.displayText}</button>
18+
);
19+
}
20+
}
21+
22+
export default Clickable;

Practice/Express-React/frontend/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import React from 'react';
22
import ReactDOM from 'react-dom/client';
33
import './index.css';
44
import App from './App';
5+
import Clickable from './components/Clickable';
56
import reportWebVitals from './reportWebVitals';
67
import FileContent from './components/FileContent';
78

89
const root = ReactDOM.createRoot(document.getElementById('root'));
910
root.render(
1011
<div>
1112
<FileContent />
13+
<Clickable displayText="Clickable Button" />
1214
</div>
1315
);
1416

0 commit comments

Comments
 (0)