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

minska-react

v1.1.1

Published

React helpers for minska

Downloads

29

Readme

minska-react

React helpers for minska.

Install

yarn add minska-react

The packages includes ES modules for Webpack 2 and Rollup, CommonJS modules for Node > 6, and Browser modules.

You can also access the files on unpkg where you can link them directly in a <script> tag and have window.MinskaReact available in global scope. The browser builds are compiled minska-react.js and minska-react.min.js.

Usage

See minska to see how to set up a store and how it works.

minska-react exports <Provider> and connect(). They work in a similar fashion to react-redux in that the Provider component passes it's store prop as context, and connected components hook into the store to provide the state to the components they wrap.

<Provider>

You first wrap your app component, or anything that might want access to the store in a <Provider>. Important: You should only have a single Provider in your app.

You give it a single prop: store. This should be an instance of a minska store. All Provider does is make the store instance available in context. You shouldn't interact with the store instance directly—instead use connect() (explained below).

import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'minska-react';
import store from './store';
import MyApp from './MyApp';

render(
  <Provider store={store}>
    // If `MyApp` is a connected component,
    // it will have access to the store
    <MyApp />
  </Provider>,
  document.getElementById('app')
);

connect()

Connecting a component passes the stores current state as props, along with the send function allowing the connected component to change the state.

In a similar fashion to react-redux, you can also choose what part of the state is passed to the connected component as props. Simply pass a function to connect that returns a slice of the state. Only that slice will be passed on as props instead of the whole state tree.

import React from 'react';
import { connect } from 'minska-react';

const MyApp = ({ count, send }) => {
  const onClick = () => {
    send('incrementBy', 1);
  }

  return (
    <div>
      <h1>Current count: {count}</h1>
      <button onClick={onClick}>+ 1</button>
    </div>
  );
};

// Given the state: `{ count: 1, foo: 'bar' }`
const mapStateToProps = (state, ownProps) => {
  // You also have access to the components original props with `ownProps`
  return { count: state.count };
};

// Then `MyApp` will only be given `count` and `send` as props
export default connect(mapStateToProps)(MyApp);