New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-thunk

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-thunk

Functional stateless React components returning thunks

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

react-thunk

Define React functional stateless components as thunks

Install

npm i --save react-thunk

Why?

Instead of doing the following, and setting a new change listener on each render:

function NameField(props) {
    const { name, setName } = props;

    return <input type="text" value={ name } onChange={ (evt) => setName(evt.target.value) } />;
}

Do the following, and only define your change listener once:

function NameField(initialProps) {
    const { setName } = initialProps;
    const changeHandler = (evt) => setName(evt.target.value);

    return (props) => {
        const { name } = props;

        return <input type="text" value={ name } onChange={ changeHandler } />;
    };
}

How?

It creates a class for you: https://github.com/troch/react-thunk/blob/master/modules/index.js. That is all the source code.

API

thunk(component: Function[, pure: Boolean])

Since a thunk creates a class, it gives you the opportunity to have pure components (set second argument to true).

import React from 'react';
import thunk from 'react-thunk';

function NameField() {
    /* ... */
}

export default thunk(NameField);

Keywords

React

FAQs

Package last updated on 19 Apr 2016

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