Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

immutable-state-helper

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immutable-state-helper

Immutable.js helper functions for React.js

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

immutable-state-helper

npm version CI report immutable-state-helper dependency status immutable-state-helper devDependency status

Install

npm install immutable-state-helper

createImmState

Helper function for setState pattern.

Copy and modify from Immutable-as-React-state.

Signature

createImmState(thisArg, [field], [callback]): Function

Arguments

  • thisArg (*): The this binding of React Element.
  • [field='data'] (String): The property name that stored in state.
  • [callback] (Function): The callback apply into setState's callback.

Returns

(Function): Immutable version of setState.

Example

import React from 'react';
import { Map } from 'immutable;
import { createImmState } from 'immutable-state-helper';

class Example extends React.Component {

  ...

  onFooChange(value) {
    this.setImmState(
      updater => updater.set('foo', value),
      () => console.log('re-rendered!')
    );
  }

  constructor(props) {
    super(props);

    this.state = {
      immData: Map({
        foo: '',
        bar: ''
      })
    }

    this.setImmState = createImmState(this, 'immData');
  }

  render() {
    const { immData } = this.state;

    return <div>{ immData.get('foo', '') }</div>;
  }
}

Keywords

immutable

FAQs

Package last updated on 10 Aug 2015

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