npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@devlander/higher-order-components

v0.0.13

Published

A comprehensive collection of higher-order components for React and React Native projects, enhancing functionality and development efficiency.

Downloads

99

Readme

Devlander Higher Order Components Collection Header

Hits

Devlander React Native Higher Order Components Collection

Introduction

The Devlander React Native Higher Order Components Collection is a comprehensive library of React Native higher-order-components, designed for seamless integration and addressing common development challenges. This collection streamlines your development process, offering versatile, cross-platform solutions for a variety of use cases.

Featured higher-order-components

  • withBorders: Wraps a container with borders for the sake of troubleshooting where views/divs end.
  • withLogProps: Logs props in a component.
  • withVisibilitySensor: Detects if a component is visible or not and passes an isVisible property down to the next component, which can be used to pass to another function.
  • withMediaQueryInfo: Keeps track of the size of the device and viewport, and returns a list of booleans. These are used to do conditional logic when rendering components on different devices, making things responsive.
  • withViewSize: Keeps track of the height and width of the component it is wrapping.
  • withSpinner: Displays a spinner while the wrapped component is in a loading state.

Installation

You can install the Devlander React Native Higher Order Components Collection using npm or yarn:

npm

npm install @devlander/higher-order-components

yarn

yarn add @devlander/higher-order-components

Usage

withBorders

import React from "react";
import { View, Text } from "react-native";
import { withBorders } from "@devlander/higher-order-components";

interface MyComponentProps {
  message: string;
  withBorders?: boolean;
  borderColor?: string;
}

const MyComponent: React.FC<MyComponentProps> = ({ message, withBorders, borderColor }) => (
  <View>
    <Text>{message}</Text>
  </View>
);

const EnhancedComponent = withBorders(MyComponent);

// Usage example
<EnhancedComponent message="Hello, world!" withBorders={true} borderColor="blue" />

withLogProps

import React from "react";
import { View, Text } from "react-native";
import { withLogProps } from "@devlander/higher-order-components";

interface MyComponentProps {
  message: string;
}

const MyComponent: React.FC<MyComponentProps> = ({ message }) => (
  <View>
    <Text>{message}</Text>
  </View>
);

const EnhancedComponent = withLogProps(MyComponent);

// Usage example
<EnhancedComponent message="Hello, world!" />
// This would console.log("Actual Props: ", { message: "Hello, world!" })

withVisibilitySensor

import React from "react";
import { View, Text } from "react-native";
import { withVisibilitySensor } from "@devlander/higher-order-components";

interface MyComponentProps {
  isVisible: boolean;
  message: string;
}

const MyComponent: React.FC<MyComponentProps> = ({ isVisible, message }) => (
  <View>
    <Text>{isVisible ? "Visible" : "Not Visible"}: {message}</Text>
  </View>
);

const EnhancedComponent = withVisibilitySensor(MyComponent);

// Usage example
<EnhancedComponent message="Hello, world!" />

withMediaQueryInfo

import React from "react";
import { View, Text } from "react-native";
import { withMediaQueryInfo, WithMediaQueryProps } from "@devlander/higher-order-components";

interface MyComponentProps extends WithMediaQueryProps {
  message: string;
}

const MyComponent: React.FC<MyComponentProps> = ({ mediaQueryInfo, message }) => (
  <View>
    <Text>{mediaQueryInfo.large ? "Large Screen" : "Small Screen"}: {message}</Text>
    <Text>Media Query Info:</Text>
    <Text>xSmall: {mediaQueryInfo.xSmall.toString()}</Text>
    <Text>Small: {mediaQueryInfo.small.toString()}</Text>
    <Text>Medium: {mediaQueryInfo.medium.toString()}</Text>
    <Text>Large: {mediaQueryInfo.large.toString()}</Text>
    <Text>xLarge: {mediaQueryInfo.xLarge.toString()}</Text>
    <Text>xxLarge: {mediaQueryInfo.xxLarge.toString()}</Text>
    <Text>Platform: {mediaQueryInfo.platform}</Text>
  </View>
);

const EnhancedComponent = withMediaQueryInfo(MyComponent);

// Usage example
<EnhancedComponent message="Hello, world!" />

withSpinner

import React from "react";
import { View, Text } from "react-native";
import { withSpinner } from "@devlander/higher-order-components";

interface MyComponentProps extends WithSpinnerProps {
  message: string;
}

const MyComponent: React.FC<MyComponentProps> = ({ message, shouldSpin, spinnerComponent }) => (
  // If `shouldSpin` is true, a spinner would show instead of this component.
  <View>
    <Text>{message}</Text>
  </View>
);

const EnhancedComponent = withSpinner(MyComponent);

// Usage example
<EnhancedComponent shouldSpin={true} message="Loading..." />

// Usage with custom spinner component
const CustomSpinner: React.FC = () => (
  <View>
    <Text>Loading...</Text>
  </View>
);

// Enhanced component with custom spinner
const EnhancedComponentWithCustomSpinner = withSpinner(MyComponent);

// In the application
<EnhancedComponentWithCustomSpinner shouldSpin={true} spinnerComponent={CustomSpinner} message="Hello, world!" />

Contributing

Contributions are welcome! Please read our contributing guidelines first.

License

This project is licensed under the Apache License - see the LICENSE file for details.

Connect with Us

Become a Sponsor!