2

I have the following code snippet, which doesn't display anything at all in the browser window. Can you please tell me why.

render(){ 
    return (
        <div>
            //Rama
            //console.log('In Render'),  
            <div>
                enter code here    
                <div>
                    <TextField    
                        hintText="Username"     
                    />
                    <br/>    
                    <TextField  
                        hintText="Password"    
                    />
                    <br/>

                    <RaisedButton label="Login" primary={true}  />  
                </div>
            <div>
            <TextField>Login Successful</TextField> 
            </div>
        </div>
    )  
}

pastebin link for complete component: http://pastebin.com/etjUwvWT

12
  • Are you importing TextField, RaisedButton, whats the error you see.., Share entire code instead of just the render function. Commented Feb 16, 2017 at 11:33
  • No errors in the console. Commented Feb 16, 2017 at 11:34
  • The entire code....import React, { Component, PropTypes } from 'react'; import { createContainer } from 'meteor/react-meteor-data'; import ReactDOM from 'react-dom'; import AutoComplete from 'material-ui/AutoComplete'; Commented Feb 16, 2017 at 11:35
  • Can I use Pastebin Commented Feb 16, 2017 at 11:35
  • update the ques with complete code :) snippet that you pasted in ques, there is a div mismatch, it should through the error, if you are using the same. Commented Feb 16, 2017 at 11:37

4 Answers 4

2

To render material-ui components you need to wrap them in MuiThemeProvider.

As Per DOC:

Beginning with v0.15.0, Material-UI components require a theme to be provided. The quickest way to get up and running is by using the MuiThemeProvider to inject the theme into your application context.

How to use these components?

First use this line to import MuiThemeProvider :

import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';

Use this render method:

render(){  
    return (
        <MuiThemeProvider muiTheme={getMuiTheme()}>
            <div>
                <div>
                    <TextField
                        hintText="Username"
                    />
                    <br/>
                    <TextField
                        hintText="Password"
                    />
                    <br/>
                    <RaisedButton label="Login" primary={true}  />
                </div>
                <div>
                    <TextField/>
                </div> 
            </div>
        </MuiThemeProvider>
    );
}

If you are using material-ui components across the project then no need to use MuiThemeProvider on each page, you also include it globally. Include this in your router or put this line on main page of the application.

One more thing you are only importing the injectTapEventPlugin, you need to initialise that also. Put this line in this component after importing:

injectTapEventPlugin();
Sign up to request clarification or add additional context in comments.

Comments

1

Looks like you're having JS-comments (//) in your JSX code. That'll make stuff break.

If you want to comment something out in JSX, you have to escape into JS with curly brackets and then use multi line comments (/* comment */) - like so:

render() {
  return (
    <div>
      {/* <button>Commented out button</button>*/}
    </div>
  );
}

1 Comment

Remove all comments from render, also make sure you have it all wrapped in MuiThemeProvider -> make sure you follow the Material-UI tutorial
1

Remove text from between the TextField tags. Also wrap your code in your render method between MuiThemeProvider. This worked for me.

render(){
  return (
      <MuiThemeProvider>
        <div>
            <div>
              <TextField
                hintText="Username"
              /><br/>
              <TextField
                hintText="Password"
              /><br/>

              <RaisedButton label="Login" primary={true}  />
            </div>

            <div> 
              <TextField></TextField>
            </div>
        </div>
      </MuiThemeProvider>

   ); 
}

1 Comment

I am glad I could help. Can you please mark my answer green?
0

As an FYI, so it is not the most obvious responses, but just in case this is your situation, my issue was that I had changed my Windows 10 personalise settings to use contrast and my blue bar in my React app disappeared! After a while of searching, I switched it off and my bar was back.

Comments

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.