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

@forrestjs/react-root

v0.7.1-alpha.4

Published

- It renders the App's root component using the local ReactDOM library - It facilitates the App's wrapping with stuff like ReactRouter or ApolloContext - It provides hooks to access the App's `config` and `context`

Downloads

58

Readme

@ForrestJS/react-root

  • It renders the App's root component using the local ReactDOM library
  • It facilitates the App's wrapping with stuff like ReactRouter or ApolloContext
  • It provides hooks to access the App's config and context

You can play with this documentation LIVE in CodeSandbox:

Edit kitchensink

Render the App's Root

First, we can create an AppRoot.js component that can access the App's configuration via React hooks:

import { useGetConfig } from '@forrestjs/react-root';

export const AppRoot = () => {
  const value = useGetConfig('welcome.message');
  return <div>{value}</div>;
};

Now we can package our App using ForrestJS:

import forrestjs from '@forrestjs/core';
import reactRoot, { getConfig } from '@forrestjs/react-root';
import { AppRoot } from './AppRoot';

// Your App should have one feature that implements the
// REACT_ROOT_COMPONENT hook to provide the... root component:
const rootEl = ['$REACT_ROOT_COMPONENT', { component: AppRoot }];

forrestjs
  .run({
    settings: {
      welcome: {
        message: 'Hello World',
      },
    },
    services: [reactRoot],
    features: [rootEl],
  })
  .catch((err) => console.error(`Boot: ${err.message}`));

Add Application's Wrappers

More often than not, your App will require one or more wrappers for providing some form of context. Think at libraries like: react-router, apollo-client, react-query, mui;

They all do add a ContextProvider in the index.js:

ReactDOM.render(
  <ApolloProvider>
    <MuiThemeProvider>
      <ReactRouterProvider>
        <MyCustomProvider>
          <App />
        </MyCustomProvider>
      </ReactRouterProvider>
    </MuiThemeProvider>
  </ApolloProvider>,
  document.getElementById('root'),
);

Looks familiar? Before the advent of Promises we were used to a similar pattern and it was oftend referenced as the Callbacks Hell.

Now we simply have a new one:
The Wrappers Hell

ForrestJS simplifies this situation by providing a flat and declarative way to decorate your App with wrappers AND maintain a decoupled structure in your apps.

Let's create a simple App wrapper in AppWrapper.js:

export const AppWrapper = ({ children }) => {
  return (
    <div>
      <h4>This is a Wrapper</h4>
      <hr />
      {children}
    </div>
  );
};

Now we can decorate our App with this wrapper using the hooks in index.js:

import { AppWrapper } from './AppWrapper';

// Create a ForrestJS single hook feature:
const wrap1 = {
  target:'$REACT_ROOT_WRAPPER',
  handler:{ component: AppWrapper }
};

// Add the feature to the App, the order doesn't matter:
runHookApp({
  ...
  features: [rootEl, wrap1]
});

Other services provided by ForrestJS simply build on this hook: