Skip to content

Commit

Permalink
Prevent rerender when a button callback returns false. (#7197)
Browse files Browse the repository at this point in the history
Prevent rerender when a button callback returns false.
  • Loading branch information
ndelangen authored and shilman committed Jul 31, 2019
1 parent fc0e049 commit 4b98d59
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions addons/knobs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ const groupId = 'GROUP-ID1';
button(label, handler, groupId);
```

Button knobs cause the story to re-render after the handler fires, you can prevent
this by having the handler return false.

### withKnobs options

withKnobs also accepts two optional options as story parameters.
Expand Down
5 changes: 3 additions & 2 deletions addons/knobs/src/registerKnobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ function knobChanged(change) {

function knobClicked(clicked) {
const knobOptions = knobStore.get(clicked.name);
knobOptions.callback();
forceReRender();
if (knobOptions.callback() !== false) {
forceReRender();
}
}

function resetKnobs() {
Expand Down

0 comments on commit 4b98d59

Please sign in to comment.