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

responsive-redux

v1.0.9

Published

Responsive state management for redux. Works with React and React Native.

Downloads

3

Readme

responsive-redux

Responsive state management for Redux. Works with React and React Native.

Installation

Install responsive-redux with npm.

npm install --save responsive-redux

Features

  • Works in React and React Native
  • Developer defined breakpoints
  • Uses just one event listener
  • One place in code that calculates the current breakpoint
  • Uses reselect style selector to provide a single source for getting responsive state

Examples

React example code

React Native example code

Example

// MyComponent.js

import React from "react";
import { connect } from "react-redux";
import { getResponsive } from "responsive-redux";

// optional for React Native
import { View, Text } from "react-native";

class MyComponent extends React.Component {
  render() {
    // grab the responsive state off of props
    const { responsive } = this.props;

    let message = `The viewport's current media type is: ${
      responsive.mediaType
    }. `;

    if (responsive.lessThan.small) {
      message +=
        'Secret message for viewports smaller than than the "small" breakpoint!';
    } else if (responsive.lessThan.medium) {
      message +=
        'Secret message for viewports between the "small" and "medium" breakpoints!';
    } else {
      message += 'Message for viewports greater than the "medium" breakpoint.';
    }

    // React Native
    return (
      <View>
        <Text>{message}</Text>
      </View>
    );

    // React web
    return <p>{message}</p>;
  }
}

const mapStateToProps = (state, ownProps) => {
  // use the getResponsive() selector
  const responsive = getResponsive(state);

  return {
    responsive
  };
};

export default connect(mapStateToProps)(MyComponent);

The Responsive State

The reducer provided by responsive-redux adds the following to the Redux store. The getResponsive() selector returns the responsive object.

  • top-level Redux store
    • responsive
      • breakpoints: (object) A duplicate of the developer-defined breakpoints object. An object keyed by breakpoint name with values of the pixel width of the breakpoint.
      • dimensions: {object} An object with keys width and height and values of the current width and height of the viewport.
      • greaterThan: (object) An object keyed by breakpoint name with values of booleans that indicate whether the viewport is currently greater than the breakpoint.
      • is: (object) An object keyed by breakpoint name with values of booleans that indicate whether the viewport is currently that particular breakpoint.
      • lessThan: (object) An object keyed by breakpoint name with values of booleans that indicate whether the viewport is currently less than the breakpoint.
      • mediaType: (string) The largest breakpoint category that the viewport satisfies.
      • orientation: (string) The viewport orientation. Has three possible values: "portrait", "landscape", or null.

Using the object returned from the getResponsive() selector, you can access the viewport's current media type like so:

// get the current responsive state using the getResponsive() selector
responsive = getResponsive();

// media type (e.g. "large")
responsive.mediaType;

// orientation
responsive.orientation;

// true if width is greater than the "medium" breakpoint
responsive.greaterThan.medium;

// true if mediaType === 'small'
responsive.is.small;

Using Custom Breakpoints

Breakpoints are defined by you, the developer. See the links to React and React Native code examples above.

The Infinity Media Type

When the viewport is wider than the largest breakpoint, its mediaType value is infinity.


Thanks

This project was inspired by redux-responsive