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

@cawfree/react-jsx-provider

v1.0.25

Published

A React Provider for reliably rendering dependency-aware distributed JSX.

Downloads

46

Readme

@cawfree/react-jsx-provider

A React <Provider/> used to reliably rendering dependency-aware JSX. Compatible with both react and react-native.

🤔 About

This library is built on top of the awesome react-jsx-parser, which is used to take a raw JSX string and render it as part of the React DOM, and adds a couple of utilities to enhance the scalability and portability of the JSX. This is done by defining a package.json-esque string which defines not only the content to render, but the necessary data dependencies of the runtime environment.

If all of the dependencies are met by the runtime, the JSX string can be injected and rendered within the DOM; otherwise, it falls back to a renderFailure method, which allows your app to continue as normal. Since it is backed by a React.createContext <Provider/>, these runtime dependencies can be referenced or overriden throughout the nested hierarchy.

🚀 Getting Started

Using npm

npm install --save @cawfree/react-jsx-provider

Using yarn

yarn add @cawfree/react-jsx-provider

✍️ Example

import React from 'react';
import {
  View,
  Text,
  StyleSheet,
  Image,
} from 'react-native';

import Provider, { ScriptComponent } from '@cawfree/react-jsx-provider';

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'white',
  },
  error: {
    flex: 1,
    backgroundColor: 'lightgrey',
    alignItems: 'center',
    justifyContent: 'center',
  },
  errorText: {
    fontSize: 60,
    fontWeight: 'bold',
    color: 'white',
  },
});

// XXX: This file contains a package.json-esque JSON which
//      defines the dependencies of the JSX wished to embed
//      within the application..
const request = require('./assets/json/package.json');

export default class App extends React.Component {
  constructor(nextProps) {
    super(nextProps);
    this.__renderFailure = this.__renderFailure.bind(this);
  }
  // XXX: This is the fallback render method for when a <ScriptComponent/>
  //      fails to have its dependency requirements met.
  __renderFailure(resolutionErrors) {
    return (
      <View
        style={styles.error}
      >
        <Text
          style={styles.errorText}
        >
          {'?'}
        </Text>
      </View>
    );
  }
  // XXX: Define the runtime implementations for each library dependency
  //      that you wish to expose to a <ScriptComponent/>.
  __getRuntime() {
    return {
      ...require('./package.json'),
      "config": {
        "react-native": {
          // XXX: Try commenting out some of the dependencies!
          View,
          Text,
          Image,
        },
      },
    };
  }
  render() {
    // XXX: The Provider is used to define the runtime implementation context
    //      for all of the child <ScriptComponent/>s. Use this at the root of
    //      your application, or nest multiple instances to define child-specific
    //      runtime dependencies.
    //
    //      The "script" prop is used to select which JSX string to render within
    //      the ScriptComponent. This is defined as part of the request package.json.
    //
    //      Try changing it to the name of a script that doesn't exist!
    return (
      <Provider
        renderFailure={this.__renderFailure}
        request={request}
        runtime={this.__getRuntime()}
      >
        <View
          style={styles.container}
        >
          <ScriptComponent
            script="Welcome"
          />
        </View>
      </Provider>
    );
  }
}

Check out the React Native app in the examples folder for more info.

🙏 Acknowledgements

react-jsx-parser

semver

✌️ License

MIT