0

I have a dialog based on material-ui written with React and mobx, I'm pretty new to mobx+react and trying to understand the lifecycle here.

The component looks something like this:

@observer
export default class AddDialog extends React.Component {

    constructor(store, props) {
        super(props);
        this.store = store;
    }

    handleClose = () => {
        this.props.store.setOpen(false);
    }

    handleDateChange = (e, date) => {
        this.props.store.setDate(date);
    }

    handleTitleChange = (e, title) => {
        this.props.store.setTitle(title);
    }

    render() {
        const actions = [
            <FlatButton
                label="Ok"
                primary={true}
                keyboardFocused={true}
                onClick={this.handleClose}
            />,
        ];

        return (
            <div>
                <Dialog
                    title="Title"
                    actions={actions}
                    modal={false}
                    open={this.props.store.open}
                    onRequestClose={this.handleClose}
                >
                    <TextField hintText="title?" onChange={this.handleTitleChange}/>
                    <DatePicker hintText="Due date" onChange={this.handleDateChange}/>
                </Dialog>
            </div>
        );
    }
}

And in App.js I have a code that looks like this:

@observer
class App extends PureComponent {
    render() {
        return (
            <MuiThemeProvider>
                <FloatingActionButton onClick={this.handleOpenAddPromissDialog}>
                    <ContentAdd />
                </FloatingActionButton>
                <AddPromissDialog store={this.props.addPromissStore} open={false}/>
            </MuiThemeProvider>
        );
    }
}

When I debug the code, it looks like both the store and props args that are passed to the constructor are initialized with the values passed in the render function. But when the handleClose is called both this.props and this.store are undefined. I can't understand what I'm missing here.

Edit: I tried printing the variables to the console, and there they don't appear as undefined but populated as I would expect. So it looks like and IntelliJ issue.

That's the debug configuration I'm using: enter image description here

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Avi
  • 21,182
  • 26
  • 82
  • 121
  • just running thru basic scenario/questions: is your project defined as a static web project? did you run `npm install` to get all dependencies? maybe go through the checks outlined in their help to see if something is missing: https://www.jetbrains.com/help/idea/react.html#starting_with_existing_react_application – blurfus Jan 09 '18 at 21:30
  • 1
    https://stackoverflow.com/q/28388530/2694656 – Nir Weber Jan 09 '18 at 21:36
  • @NirWeber not sure the linked issue is related. That one seems to be a Chrome issue - the OP is asking about intelliJ (or webstorm) properties and their auto-resolve ability with reactjs... – blurfus Jan 09 '18 at 22:14

1 Answers1

3

the problem is caused by the way Babel transpiles this in arrow functions: it is changed to _this in transpiled code, and no name mappings are provided:

enter image description here

You will face the same issue when debugging in Chrome Dev Tools (that use the same API as WebStorm for debugging):

enter image description here

See Value of "this" is incorrect when debugging Babel transpiled React with Chrome Devtools and similar reports

lena
  • 90,154
  • 11
  • 145
  • 150