Showing posts with label React-Native. Show all posts
Showing posts with label React-Native. Show all posts

Thursday, April 28, 2022

Higher Order Components

Higher Order Components in React-Native


A Higher order component is a component that take a component as a input and returns a new component.


A higher order component  is react technique for reuse component logic.


HOCs basically incorporate the don’t-repeat-yourself (DRY) principle of programming, which you’ve most likely come across at some point in your career as a software developer. It is one of the best-known principles of software development, and observing it is very important when building an application or writing code in general.


The most interesting part of using higher-order functions is composition. We can write small functions that handle one piece of logic. Then, we can compose complex functions by using the different small functions we have created. This reduces bugs in our code base and makes our code much easier to read and understand.


import React from 'react';

// Take in a component as argument WrappedComponent

const higherOrderComponent = (WrappedComponent) => {

// And return another component

  class HOC extends React.Component {

    render() {

      return <WrappedComponent />;

    }

  }

  return HOC;

};

Java Script

  1 Feb 2024 (1) Find the Second largest number in the array: - const findSecondLargest=(a)=>{     var largestNumber = 0;     var secondL...