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

@asyncapi/generator-react-sdk

v1.0.18

Published

The React SDK for templates.

Downloads

216,137

Readme

AsyncAPI React SDK

AsyncAPI React SDK is a set of components/functions to use React as render engine in the Generator.

Installation

Run this command to install the SDK in your project:

npm install --save @asyncapi/generator-react-sdk

How it works

The process of creating content from React components consists of two main process: transpile and rendering.

The Transpile Process

The SDK has a custom transpiler which ensures that any directory are transpiled using Rollup. Rollup helps bundling all dependencies and transpile them into CommonJS modules. This is required because this library will be used through NodeJS which does not understand these new modules natively and we do not want to limit the developer in which syntax they prefer nor how they want to separate code.

The Rendering Process

SDK has its own reconciler for React components. It traverses through each element in the template structure and transforms it into a pure string. Additionally, prop children is also converted to a regular string and stored in the childrenContent prop, which is appended to each component. See example.

Restrictions:

  • React hooks is not allowed.
  • HTML tags at the moment is not supported.
  • React internal components like Fragments, Suspense etc. are skipped.

Requirements

To render the transpiled template SDK requires:

  • Node.js v18 and higher

The debug flag

When rendering you have the option of passing a debug flag which does not remove the transpiled files after the rendering process is done.

Example

import { Text, Indent, IndentationTypes, render } from '@asyncapi/generator-react-sdk';

class ClassComponent extends React.Component {
  constructor(props) { 
    super(props);
  }

  render() {
    // In `childrenContent` prop is stored `text wrapped by custom component\n\n`.
    // The content of the `children` prop is transformed to string and saved to the `childrenContent` prop.
    return this.props.childrenContent;
  }
}

function FunctionComponent() {
  return (
    <Indent size={3} type={IndentationTypes.TABS}>
      indented text
      <ClassComponent>
        <Text newLines={2}>
          text wrapped by custom component
        </Text>
      </ClassComponent>
    </Indent>
  );
}

// content will be `\t\t\tindented text text wrapped by custom component\n\n`
const content = render(<FunctionComponent />);

Resources

  • template-for-generator-templates template showcases features of the AsyncAPI Generator, including the React renderer. It shows how to write templates, reusable parts (components), what are the recommended patterns. It has simple and complex examples of using React.
  • markdown-template is written using React. It generates documentation into a Markdown file.

For more help join our Slack workspace.

Development

  1. Setup project by installing dependencies npm install
  2. Write code and tests.
  3. Make sure all tests pass npm test
  4. Make sure code is well formatted and secure npm run lint

Contributing

Read CONTRIBUTING guide.