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

react-native-injectable-component

v0.1.3

Published

A 'injectable' react-native component that allows an external component to be injected during run-time while fallbacking to a default component

Downloads

107

Readme

react-native-injectable-component

Travis Build Status David npm

💉 A "injectable" react-native component that allows an external component to be injected during run-time while fallbacking to a default component

What

The core of react-native-injectable-component is rather small and simple. It's sole purpose is to simplify the need of passing along an external component to override the default internal component.

Why

This rised mainly from the issue of developing open-source components, where vast users have different preferred components. The result is the typical "duck" problem -- numerous types and variations available, but they are simply ducks 🦆🦆🦆.

Thus, this component is essentially a high-order component with a strategy pattern in mind. Therefore, as long as the injected component (injectant) implements the same core interface, things will render visually identical. On top of that, we can pass along particular props for added flexibility.

When

Use react-native-injectable-component for building components where there is a strong indication where you suspect the component may be replaced in the future. In addition, where you want to give users greater flexibility without having to touch the core code of your components.

Install

$ npm install react-native-injectable-component --save

Usage

  1. Add an import to the top of your file
    import Injector from 'react-native-injectable-component';
  2. Declare a defaultComponent for the Injector, and include a way to dynamic pass along an optional Injectant component and properties. This will allow a component to overload default implementation, and add extra props if needed.
    const myComponent = (props) => {
        const imageProps = {
            source: {
                uri: "https://test.com/image1.jpeg"
            },
            resizeMode: "contain"
        };
           
        render() {
            return (
                <Injector
                   defaultComponent={Image}
                   defaultProps={imageProps}
                   injectant={props.customComponent}
                   injectantProps={props.customComponentProps}
                />
            )
        }
    }
  3. Now myComponent will render Image by default, but users can now have the ability to use their own third-party Image component if needed.

Component Props

| Property | Type | Description | |------------------|----------------------------|--------------------------------------------------------------------------------------------------------------------------------| | defaultComponent | func - react component | A default component to be used unless a injectant is specified | | defaultProps | object | Default properties that are applied in both components | | injectant | func - react component | A component that will override the defaultComponent for rendering. Note: this component should abide by a same core interface. | | injectantProps | object | Props that will assign over defaultProps and be applied to the injectant rendering. |

Examples

These are example repositories / components that are currently using react-native-injectable-component.

Contribute

While the core of this module is small, feel free to submit issues or provide suggestions on improving usability.

License

MIT © Brandon Him