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

react-mobx-preload

v0.0.1

Published

A library providing preloading promise-based functionality for react & mobx components

Downloads

4

Readme

React-MobX-Preload

A small library providing preloading promise-based functionality for react & mobx components.

Getting Started

Simple setup using yarn or npm setup.

yarn add react-mobx-preload

or

npm install react-mobx-preload --save

Usage

There are two features react-mobx-preload provides. There is a connect decorator and preload decorator. Both can be used by importing either createConnect or createPreloader from react-mobx-preload package. Choice to provide those create function was made, becouse you might want to use different MobX stores related to connect and preload decorators, or you might want to have a different <Preloader /> component for each of Components you'll use preload on.

Connect

You can create one global connect wired to all stores, or make a connect for each store. I'd advise you to create a connect in module, where you have the store, so you know, what you can expect in your connect decorator.

import UIStore from './uistore';
import CustomerStore from './customerStore';

const Store = {
  UIStore,
  CustomerStore
};

export const connect = createConnect(Store);
export default Store;

You can then use connect on your component like this.

import React, { Component } from 'react';
import { connect } from 'mobx/store';

@connect((store, props) => {
	const keys = store.getKeys();
    return { keyAsProp: keys };
})
export default class Comp extends Component {
	render() {
		return(
        	<div>{this.props.keyAsProp}</div>
        );
	}
}

Important is that connect also behaves like an observer from react-mobx library, so when anything you pass via connect changes, connect will pass you new values and rerenders your component. This makes it easier to see what data you have available in your component, and gives you convenient to do transformation of the data.

Preload

You can use many different preloaders for many different components, or you can preload only on "page" basis. It's completly up to you. That's why we have to first createPreloader.

import React, { Component } from 'react';
import { createPreloader } from 'react-mobx-preload';
import { Store } from '../Store'
import PreloadComponent from './components/Preloader';

const preloader = createPreloader(Store, PreloadComponent);

@preloader((store, props) => store.customers.loadMore(props.selectedCustomers))
export default class Comp extends Component {
	render() {
    	...
    }
}

While the promise is pending, your <PreloadComponent /> will be shown instead of your Component.