use of higher order components in react code example

Example 1: Higher order components (HOC) react native

const EnhancedComponent = higherOrderComponent(WrappedComponent);

Example 2: high level components react

import React, { useState } from 'react';

class WelcomeName extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>
  }
}

function HighHookWelcome() {
  const [name ,setName] = useState("Default Name Here");
  return(
    <WelcomeName
      name={name}
    />
  );
}

// Note: Didn't need to use state for a static value.
// Minimal example, just to illustrate passing state/props.
// setName is a function to change the name value.

Tags:

C Example