react from class to function code example
Example 1: functional components react
function Comment(props) {
return (
{props.author.name}
{props.text}
{formatDate(props.date)}
);
}
Example 2: create-react-app class component
npx create-react-app my-app --scripts-version [email protected]
Example 3: function inside a class component react
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 ;
}
}