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 Jul 7, 2019
2 parents aefedd4 + d3d8357 commit 29d9924
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 @@ -410,6 +410,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 29d9924

Please sign in to comment.