1.0.10 • Published 6 years ago

@hypersprite/toggle-state-rp v1.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Toggle State Render Props Component

Demo codesandbox.io...

This is a Render Prop Component, this style of component was introduced by Michael Jackson of react-router fame. See Official React Render Props docs for more information.

Accepts an initialState and passes as props: a toggle boolean state and three functions to update the toggle state.

Usage

Install

npm install --save @hypersprite/toggle-state-rp

Import

import ToggleState from '@hypersprite/toggle-state-rp';

Usage

Place child component inside function return and use the parameters.

parent-container.jsx

// some place in your component, you need a DialogMessage

    <ToggleState
      initialState
      render={toggleStateRP => (
        <DialogMessage
          {...toggleStateRP}
        />
      )}
    />

dialog-message.jsx

const DialogMessage = ({ toggle, handleToggle }) => {
  return (
    <div>
      <p>
        {`Toggle is: ${toggle}`}
      </p>
      <button onClick={handleToggle}>Toggle</button>
    </div>
  );
};

API

Receives Props

prop nametypevaluesdescription
initialStatebooltrue or false*Sets initial state

New Passed Props

prop nametypevaluesdescription
togglebooltrue or false*The State being toggled
handleFalsefunctionCall to set toggle to false
handleTogglefunctionCall to toggle toggle
handleTruefunctionCall to set toggle to true
1.0.10

6 years ago

1.0.9

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago