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

@blare/react-frontload

v0.0.6

Published

Bind Async Data Dependencies to React Components

Downloads

4

Readme

react-frontload

In React applications, a common requirement is to render data which is dynamically loaded from an API into a component, on both server and client renders.

react-frontload is a library that lets you declaratively bind custom data loading logic to your components, and then automatically fires the data loading when the component renders on both server and client. 

It integrates easily into your existing React stack, and importantly, requires no changes to your data API.

API

Here I'll just get straight to the API reference.

For a detailed description of the library and API, including sample code, see this blog post.

npm i --save @blare/react-frontload


frontloadConnect(frontload, [options])(Component)

frontloadConnect is the bridge between react-frontload and the Component you want to load data into.

The frontload and options parameters:

frontload(props)

A function which is called with the Component props, and returns a Promise which must resolve when all the required data-loading is complete.

[options]

The optional options object provides three configurations that specify when exactly the frontload function should fire on both client and server. If any particular configuration is left undefined, it takes its default value. Likewise, if the entire options object is left undefined, all three configurations take their default values.

noServerRender (boolean) [default false]

Toggles whether or not the Component’s frontload function will run on server render.

onMount (boolean) [default true]

Toggles whether or not the frontload function should fire when the Component mounts on the client.

onUpdate (boolean) [default true]

Toggles whether or not the frontload function should fire when the Component’s props update on the client.


Frontload

The react-frontload provider Component - it must be an ancestor of all Components in the tree that use frontloadConnect.

It is configurable with a noServerRender prop which turns off server rendering for the entire application, as a convenience so that each individual Component does not need to set noServerRender: true.


frontloadServerRender(renderFunction)

The react-frontload server render wrapper which must be used on the server.

It takes a renderFunction argument which is itself a funcion that performs the ordinary React server rendering code and returns markup. In most cases this renderFunction will just be a wrapper for a ReactDom.renderTostring call.

It returns the markup output by renderFunction, which can be sent as a response in the usual way.

The reason this wrapper function is required has to do with the way react-frontload works under the hood. You can think of serverRender as a proxy for your existing server rendering logic, that 'injects' the plumbing that makes react-frontload work.