0

I am currently having a problem rendering a React wrapper component in another component. Basically, I export default the wrapper component (CreatePage), and then try to import it into another component (EditPage), but am getting the error "Cannot read property pageType of undefined." pageType is a prop for CreatePage that I define, but the weird thing is I have debuggers in the render functions of both Components and neither is being hit, so I think there's an issue with the component itself for some reason but I'm not sure quite what. Here is the code from the EditPage for some context:

import React, { Component, PropTypes } from 'react';
import CreatePage from './CreatePage';
import withResource from '../../../../lib/withResource';


export class EditPage extends Component {
    constructor(props){
        super(props);
    }

    render() {
        debugger;
        return (
            <div>
                <CreatePage pageType={'edit'}/>
            </div>
        );
    }
}

export default withResource(
{
    name: 'EditResource',
    key: 'hello',
    }, 
EditPage);

Code for CreatePage:

export default class CreatePage extends Component {

    constructor(props) {
        super(props);
    }

    headerTitles = {
        'create': i18n._('Create', '[m10n]'),
        'edit': i18n._('Edit', '[m10n]'),
    }

    renderHeader(pageType) {
        return (
            <div className={cx('headerWrapper')}>
                <div className={cx('header')}>
                    <div className={cx('title')}>
                        {this.headerTitles[pageType]}
                    </div>
                </div>
            </div>
        );
    }

    renderCreateEditPage(pageType) {
        return (
            <div>
                {this.renderHeader(pageType)}
                <div className={cx('contentWrapper')}>
                    <div>
                        <NameTag type={'pageType'}/>
                    </div>
                </div>
            </div>
        );
    }

    render() {
        return (
            <div className={cx('pageWrapper')}>
                {this.renderCreateEditPage(this.props.options.pageType)}
            </div>
        );
    }
}
2
  • Can you provide code of CreatePage? Commented Jul 30, 2016 at 22:08
  • Just added it to the post as an edit. Commented Jul 31, 2016 at 0:39

1 Answer 1

2

CreatePage is looking in this.props.options.pageType but you just passed in pageType directly.. no mention of an options prop

Sign up to request clarification or add additional context in comments.

1 Comment

Totally overlooked this! It's working now, I really appreciate it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.