Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using setState in externaly controlled custom callback #781

Closed
sum32 opened this issue Dec 21, 2017 · 3 comments
Closed

Using setState in externaly controlled custom callback #781

sum32 opened this issue Dec 21, 2017 · 3 comments

Comments

@sum32
Copy link

sum32 commented Dec 21, 2017

Griddle version

1.11.0

Expected Behavior

  • A Trigger function exists in an external context:
extTrigger(){
  console.log("EXT TRIGGER");
  this.setState({ extVar: 1 })
}
  • During extrenal control of Griddle through a react component it is possible to pass a callback function in Griddle properties(stories/index.tsx):
    <Griddle extTrigger={this.extTrigger} data={fakeData} plugins={[LocalPlugin, LocalCustomPlugin]}>

  • This can then be obtain it in a Container component, like TableContainer(src/plugins/localCustomPlugin/components/TableBodyContainer.js):

connect((state, props) => ({
   visibleRowIds: props.visibleRowIdsSelector(state),
   className: classNamesForComponentSelector(state, 'TableBody'),
   style: stylesForComponentSelector(state, 'TableBody'),
   extTrigger: ((state)=>{return state.get('extTrigger')})(state),
 })),
)(({ Row, visibleRowIds, style, className, extTrigger }) => (
 <OriginalComponent
   rowIds={visibleRowIds}
   Row={Row}
   style={style}
   className={className}
   extTrigger={extTrigger}
 />
  • And finally the extTrigger function can be used as a callback in TableBody(src/plugins/localCustomPlugin/components/TableBody.js):
<tbody style={style} className={className}>
      { rowIds && rowIds.map((k, i) => <Row key={k} griddleKey={k} index={i} />) }
      <tr>
      <td colSpan="3">
       This Button will use an external callback, brought in by the TableContainer (set in Griddle props), This trigger will print something and try to set state in the external context, but It fails
       <button onClick={extTrigger}> Try me </button>
      </td>
      </tr>
    </tbody>
  • The state variable in the external context changes but Griddle just loses all data

Actual Behavior

The data should still show up in Griddle.

Steps to reproduce

Just load the story

Controlling external state through a callback

and press

Try me

Griddle will break but the state variable in the external context will change as expected.

Pull request with failing test or storybook story with issue

#782

@sum32 sum32 changed the title External control callback setState Using setState in externaly controlled custom callback Dec 21, 2017
@sum32 sum32 mentioned this issue Dec 23, 2017
@dahlbyk
Copy link
Contributor

dahlbyk commented Dec 23, 2017

I'm pretty sure your issues don't have anything to do with external state, but rather inconsistent prop/state handling that seems to have been introduced by #756. I'm trying to come up with a more specific repro.

dahlbyk added a commit to dahlbyk/Griddle that referenced this issue Dec 24, 2017
dahlbyk added a commit to dahlbyk/Griddle that referenced this issue Dec 24, 2017
@dahlbyk
Copy link
Contributor

dahlbyk commented Dec 24, 2017

This should be fixed as of 1.11.1.

@sum32
Copy link
Author

sum32 commented Dec 25, 2017

Thanks!:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants