Git Product home page Git Product logo

react-window-dimensions's Introduction

react-window-dimensions

Build Status

A higher order component that can be used to inject the window dimensions into your component as properties.

Installation

npm i -S react-window-dimensions

Basic Usage

import React from 'react';
import windowDimensions from 'react-window-dimensions';

const MyComponent = ({ width, height }) => (
  <div>
    The window is {width} x {height}!
  </div>
);

export default windowDimensions()(MyComponent);

Advanced Usage

import React from 'react';
import windowDimensions from 'react-window-dimensions';
import debounce from 'lodash.debounce';

const MyComponent = ({ windowWidth }) => (
  <div>
    The window is {windowWidth} pixels wide!
  </div>
);

export default windowDimensions({
  take: () => ({ windowWidth: window.innerWidth }),
  debounce: onResize => debounce(onResize, 100),
})(MyComponent);

Options

There are several options you can use to alter the higher order component:

  • take - a function that maps the window to props that are passed into the wrapped component (default: (props) => ({ width: window.innerWidth, height: window.innerHeight }))
  • debounce - a function that debounces the resize event handler (default: fn => fn)

Contributing

Pull requests are welcome. Code style is inherited from airbnb-base and enforced by eslint. You can check that your changes respect the code style by running the lint command:

npm run lint

If you're submitting a bugfix, a test to document (and prevent) the issue is welcome.

react-window-dimensions's People

Contributors

bharley avatar

Watchers

James Cloos avatar Josh Hawkins avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.