classes react code example

Example 1: class in react

class App extends Component {
    constructor() {
        super()
        this.state = {
            name: "Sally",
            age: 13
        }
    }
    
    render() {
        return (
            

{this.state.name}

{this.state.age} years old

) } }

Example 2: create react component class

class MyComponent extends React.Component{
    constructor(props){
        super(props);
    };
    render(){
        return(
            

My First React Component!

); } };

Example 3: react class component

class Welcome extends React.Component {
  render() {
    return 

Bonjour, {this.props.name}

; } }

Example 4: functional components react

function Comment(props) {
  return (
    
{props.author.name}
{props.author.name}
{props.text}
{formatDate(props.date)}
); }

Tags:

Misc Example