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

Setting up theme manager: Invariant Violation: t.getChildContext(): childContextTypes must be defined in order to use getChildContext(). #1891

Closed
kkotwal94 opened this issue Oct 15, 2015 · 3 comments
Labels
customization: theme Centered around the theming features package: system Specific to @mui/system

Comments

@kkotwal94
Copy link

I copied this example from the docs into my own component, first time using it, no idea what to do to fix the error in the title.

Childcontext types is defined tho

Is it because of the parent? Should the parent set the context?

import React from 'react';
import {Link} from 'react-router';
import UserActions from 'actions/UserActions';
import UserStore from 'stores/UserStore';
import Immutable from 'immutable';
const RaisedButton = require('material-ui/lib/raised-button');
const Dialog = require('material-ui/lib/dialog');
const ThemeManager = require('material-ui/lib/styles/theme-manager');
const LightRawTheme = require('material-ui/lib/styles/raw-themes/light-raw-theme');
const Colors = require('material-ui/lib/styles/colors');

export default class Profile extends React.Component {


  childContextTypes: {
    muiTheme: React.PropTypes.object
  }

    constructor(props) {
    super(props);
    this.state = UserStore.getState();
    this.state.muiTheme = ThemeManager.getMuiTheme(LightRawTheme);
  }

  getChildContext() {
    return {
      muiTheme: this.state.muiTheme
    };
  }
  componentWillMount(){
    let newMuiTheme = ThemeManager.modifyRawThemePalette(this.state.muiTheme, {
      accent1Color: Colors.deepOrange500,
    });

    this.setState({muiTheme: newMuiTheme});
  }

  componentDidMount() {
    UserStore.listen(this._onChange);
  }

  componentWillUnmount() {
    UserStore.unlisten(this._onChange);
  }

  _onChange = () => {
    this.setState({
      user: UserStore.getState().user
    });
  }



  render() {

    let containerStyle = {
      textAlign: 'center',
      paddingTop: '200px',
    };

    let standardActions = [
      { text: 'Okay' },
    ];

    return (
      <div>
      <div className ="container-fluid">

            <div className="row">
                    <div className="col-lg-12">
                        <h1 className="page-header">
                            Profile <small>My Info</small>
                        </h1>
                        <ol className="breadcrumb">
                            <li className="active">
                                <i className="fa fa-dashboard"></i> <Link to ="/dashboard/main">Dashboard</Link>
                            </li>
                            <li>
                            Profile
                            </li>
                        </ol>
                        <div> Where my profile data should be
                         <div style={containerStyle}>
        <Dialog
          title="Super Secret Password"
          actions={standardActions}
          ref="superSecretPasswordDialog">
          1-2-3-4-5
        </Dialog>

        <h1>material-ui</h1>
        <h2>example project</h2>

        <RaisedButton label="Super Secret Password" primary={true} onTouchTap={this._handleTouchTap} />

      </div>
                        </div>
                    </div>
                </div>
          </div>

        </div>
    );
  }
}

@etburke
Copy link

etburke commented Oct 16, 2015

I ran into this and opted to continue using React.createClass over ES6 classes. Here's a related topic on StackOverflow: http://stackoverflow.com/questions/32078493/childcontexttypes-in-es6

@shaurya947
Copy link
Contributor

^that.

Or outside the class, you can access it using dot notation:

/*class definition...*/

//outside class
Profile.childContextTypes = {
    //child context keys
};

@oliviertassinari
Copy link
Member

@etburke have a look at #1734

mnajdova pushed a commit to mnajdova/material-ui that referenced this issue Nov 10, 2020
@zannager zannager added package: system Specific to @mui/system customization: theme Centered around the theming features labels Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: theme Centered around the theming features package: system Specific to @mui/system
Projects
None yet
Development

No branches or pull requests

5 participants