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

dust-react

v2.0.0

Published

Dust helper to render react components

Downloads

14

Readme

dust-react

A dust helper to render React components.

Features:

  • Server & client rendering (using requireJS on the client)
  • Allows passing React props as variadic or explicit params
  • Gracefully fails on rendering errors

Module Definition

dust-react provides the following ways of importing:

  • Pre-compiled ES5 code for use in non-babel'd projects (dust-react/lib, which is also the main entry point when doing require('dust-react'))
  • UMD module for use in the browser (dust-react/dist)

The module is the default export. If you're using CommonJS without babel transpiling import/exports, you'll need to explicitly reference the default export.

const dustHelperReact = require('dust-react').default;

Usage

dust-react works in both Node.js and AMD environments. Configuring the helper based on the environment allows loading modules in both contexts.

dustHelperReact(options: object)

| Option | Type | Description | | --- | --- | --- | | requireFn | Function | Required - The require function based on the environment | | globalContext | Object | Required - The global context object (global in Node.js and window in the browser) | | componentDir | String | Optional - An absolute path for requiring components in Node.js |

Example

import dust from 'dustjs-linkedin';
import dustHelperReact from 'dust-react';
import path from 'path';

dust.helpers = dust.helpers || {};
dust.helpers.react = dustHelperReact({
  requireFn: require,
  globalContext: global,
  componentDir: path.resolve(__dirname, '../component')
});

Helper

Params

| Param | Type | Description | | --- | --- | --- | | component | String |Required - the path to require the module | | props | Object | optional - Properties to be passed to React.createElement | | namedExport | String | optional - Uses the default export if not specified |

The helper requires a reference to a react component as a string. This is what is used with the require function passed in when creating the helper.

<div id="module-mount">
  {@react component="react-module" props=. /}
</div>

This equates to a require statement that looks like the following:

require('react-module');

(Note about AMD - all modules are loaded asynchronously, and the rjs optimizer is not yet supported)

Props

Props can also be variadic, allowing you to pass in params to the helper that become React props.

<div id="module-mount">
  {@react component="react-book" title='Boop' pages=10 /}
</div>

This is equivalent to:

React.createElement(ReactBook, { title: 'boop', pages: 10 });

Named Exports

By default, dust-react will use the default export of the module. You can optionally specify a named export as well.

<div id="module-mount">
  {@react component="react-module" namedExport="example" props=. /}
</div>

This is equivalent to:

const component = require('react-module').example;

// or in ES6

import { example } from 'react-module';

Component Paths

Component paths can be either a relative path or a package path.

  • Relative path: ./local-component/example (must start with a dot-slash)
  • Package path: some-npm-module

Relative Paths -- Node.js vs AMD

Under the hood, every path to a component for AMD becomes a package path. Passing in a relative path will result in requiring the module without the ./. This allows you to reference a local file for rendering server-side and reference the same file from your RequireJS baseUrl.

Tests

The tests are written in Jest.

npm test