2

When I am using create react app when compliling I get the following errors ./src/Grid.js "Line 3: Your render method should have return statement" and "Line 5: 'render' is not defined" this is the contents of the the Grid.js file

import React, { Component } from 'react';

class Grid extends Component {
    render(){
        return <p>Hello, World</p>;
    }
}

export default Grid;

I can't see that is wrong here? any help appreciated

import React, { Component } from 'react';
import Grid from './Grid.js';

class App extends Component 
{
  render()
  {
    return(
      <div> 
        <Grid />
      </div>
    );
  }
}

export default App;

This is where I am using the component

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

Where ReactDOM render is used

5
  • What happens if you use a functional component, e.g. const Grid = () => <p>Hello, World</p>; Commented Jun 6, 2017 at 13:12
  • try render() { return (some value) Commented Jun 6, 2017 at 13:13
  • can you show where you are rendering this component? Commented Jun 6, 2017 at 13:14
  • I've appended where I am rendering the component in the original question Commented Jun 6, 2017 at 13:16
  • I'm suspecting something hasn't downloaded properly when you created the create-react-app. Have you tried running npm install within the app, or perhaps just starting again and importing the files you created? Commented Jun 6, 2017 at 13:39

4 Answers 4

10

You are missing import {render} from 'react-dom';.

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

1 Comment

is it react-dom or react-router-dom?
0

It should be:

import React, { Component } from 'react';

class Grid extends Component {
    render(){
        return(<p>Hello, World</p>);
    }
}

export default Grid;

The above quote no longer applies.

I tried your exact code for Grid.js and App.js from the question and it works well on my machine. Whatever reason why your thing isn't working isn't in your Grid.js or App.js.

6 Comments

No thats not a necesity
If you're returning a one line component, brackets aren't necessary
Thanks, I'm still getting the compile issue even with the parenthesis around the jsx :(
If I remove the <Grid /> from App.js and remove the Grid import and render some plain HTML in the render function it works fine.
Wow I created a new file with the exactly the same code for the component and it compiles fine. strange.
|
0

In My case, I forget to write .Provider with my createdContext.

Comments

-1

Still no real explanation for this. Copying the component code in to a newly created file compiles correctly. Very strange indeed.

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.