Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-jax

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-jax

A tiny decorator to manage AJAX requests in React components.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-jax Build Status

A tiny higher order component to manage AJAX requests in React components.

  • Automatically aborts requests on componentWillUnmount.
  • Supports many AJAX clients.
  • Exposes components pending state as a property.
  • Abort all pending requests at will.

Example

import React from 'react';
import jax from 'react-jax';
import superagent from 'superagent';

@jax(superagent)
export default class MyComponent extends React.Component {

    sendRequest = () => {
        this.props.get('https://example.com').end((err, res) => {
          // your code
        });
    }

    render() {
        return this.props.pending ?
            <button onClick={this.sendRequest}>Click Me</button> :
            <button onClick={this.props.abort}>Cancel</button>;
    }
}

API

As a decorator
@jax(options)
export default class Test extends React.Component {
    /* your code */
}
As a function
class Test extends React.Component {
    /* your code */
}

export default jax(options)(Test);
Options

You can choose to pass a superagent client or an object for additional options.

These options can be passed to the jax() decorator.

client required
methods defaults to ['get', 'post', 'del', 'put']

Array of jax methods to expose as properties.

pendingKey defaults to pending

Property name to expose the pending status as.

abortKey defaults to abort

Property name to expose the abort function as.

endEvents defaults to ['end', 'abort', 'error']

Events emitted by the clients request object than indicate it should be cleaned up.

Properties
props[abortKey]() -> undefined

Aborts all pending requests sent by the component.

props[pendingKey] -> boolean

Returns true if any request sent by the component are pending.

props[method](...args) -> req

Exact same function signature the client exposes. For example, superagent will expose functions like these.

FAQs

Package last updated on 07 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc