I have a React component
export default class Archive extends React.Component {
...
}
componentDidMount
and onClick
You can create functions in react components. It is actually regular ES6 class which inherits from React.Component
. Just be careful and bind it to the correct context in onClick
event:
export default class Archive extends React.Component {
saySomething(something) {
console.log(something);
}
handleClick(e) {
this.saySomething("element clicked");
}
componentDidMount() {
this.saySomething("component did mount");
}
render() {
return ;
}
}