Skip to content

Commit

Permalink
Add information about transition function
Browse files Browse the repository at this point in the history
  • Loading branch information
becousae committed Dec 14, 2017
1 parent 4167620 commit c45d7b2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ npm install fsm-hoc --save
## Usage

This module provides a function to wrap your components in a finite state machine.
This gives your component to additional props: `status` and `transition`.

The status is the current status of the component.
Transition is a function that takes as first argument `this`, and as second an object with
`type` key that contains the `Action`.

### Type arguments

Expand Down Expand Up @@ -102,10 +107,20 @@ class Form extends React.Component<Props & InjectedProps<Status, Action>, State>

...

onSubmit() {
this.props.transition(this, { type: Action.Submit });
}

render() {
return (
...
<input type="button" disabled={this.props.status !== Status.Loading}>Submit</input>
<input
type="button"
disabled={this.props.status !== Status.Loading}
onClick={this.onSubmit}
>
Submit
</input>
...
);
}
Expand Down

0 comments on commit c45d7b2

Please sign in to comment.