Skip to content

A react.js wrapper component that allows you to invoke a function once mounted.

Notifications You must be signed in to change notification settings

track0x1/react-iife

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React-IIFE

A react.js wrapper component that allows you to invoke a function on mount.

Installation

React-IIFE requires React 15 or later.

npm install --save react-iife

React-IIFE uses CommonJS-style requires, which assumes you are using a module bundler like Browserify or Webpack.

Props

children [Node] required

The component you are hijacking.

fn [Function] required

The function you are calling within the context of your child component.

Note: ES6 arrow functions can not be used here because they cause this argument to be ignored. Read why...

Usage

const instantBake = function() {
    this.setState({ readyToEat: true });
}

<IIFE fn={instantBake}>
    <Cookie />
</IIFE>

Why?

Sometimes you may want to force the state of a component or call a function the moment it is mounted. This can be beneficial when demoing components in a sandbox environment like React storybook.

License

ISC

About

A react.js wrapper component that allows you to invoke a function once mounted.

Resources

Stars

Watchers

Forks

Packages