@moxy/next-with-router-ref

1.0.0 • Public • Published

next-with-router-ref

NPM version Downloads Build Status Coverage Status Dependency status Dev Dependency status

An alterntive to Next.js withRouter HOC that supports refs by forwarding them.

Installation

$ npm install @moxy/next-with-router-ref

This library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly.

Usage

import React, { Component } from 'react';
import withRouterRef from '@moxy/next-with-router-ref';

class MyComponent extends Component {
    render() {
        const { router } = this.props;

        // ...do something with router

        return <div>Hello</div>;
    }
};

export default withRouterRef(MyComponent);

...and then refs work as you would expect:

import React, { Component } from 'react';
import MyComponent from 'path/to/my-component';

const MyParentComponent = () => {
    const myComponentRef = useRef();

    return <MyComponent ref={ myComponentRef }>;
};

export default MyParentComponent;

Tests

$ npm test
$ npm test -- --watch # during development

License

Released under the MIT License.

Package Sidebar

Install

npm i @moxy/next-with-router-ref

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

8.28 kB

Total Files

6

Last publish

Collaborators

  • tiagodinis
  • moxyhq
  • filipediasf
  • satazor
  • marcooliveira
  • acostalima
  • andregoncalvesdev