functional components in 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: functional component react

function Welcome(props) {
  return 

Hello, {props.name}

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

Example 4: react functional components

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

Example 5: create functional component react

import React from 'react'; const App = () => {  const greeting = 'Hello Function Component!';   return ;}; const Headline = ({ value }) =>  

{value}

; export default App;

Example 6: functional components

function Welcome(props) {  return 

Hello, {props.name}

; } const element = ;ReactDOM.render( element, document.getElementById('root') );

Tags:

Misc Example