function component 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: react fun tion

// it a component
import React from 'react';

class App extends React.Component {
      //call function (ECMAScript 5) from tag input:text
  handleChange = e => {
    //
    console.log(`${e.target.value}`)
  }
  render() { 
    return (
      
); } } export default App;

Example 3: create react component class

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

My First React Component!

); } };

Example 4: class app extends component syntax

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

Hello, {this.props.name}

; } }

Example 5: functional component react

function Welcome(props) {
  return 

Hello, {props.name}

; } function App() { return (
); } ReactDOM.render( , document.getElementById('root') );

Example 6: react functional components

const component = () => {
console.log("This is a functional Component");
}

Tags:

Misc Example