0

react Create components to prompt errors

This is the code.

import {React,PureComponent} from 'react';
export default class chainRefeshTool extends React.PureComponent {
    render() {
        return (
            <div>
                <h1>Hello World!</h1>
            </div>
        );
    }
}

我想输出hello word! 但是页面报错 I want to output Hello word! But the page is wrong. 报错信息如下The error information is as follows:

./src/pages/BackStage/ChainRefeshTool/index.js

Line 4: Your render method should have return statement react/require-render-return

Line 5: Expected an assignment or function call and instead saw an expression no-unused-expressions

Line 5: Missing semicolon semi

Search for the keywords to learn more about each error.

1
  • Can you show how you are importing this component ? Commented Jul 9, 2019 at 3:44

2 Answers 2

1

There's nothing wrong with your code, but your import statement is incorrect; it should be:

import React, { PureComponent } from 'react';

Then you can simply extend PureComponent instead of React.PureComponent:

import React, { PureComponent } from 'react';

export default class chainRefeshTool extends PureComponent {
    render() {
        return (
            <div>
                <h1>Hello World!</h1>
            </div>
        );
    }
}

There's also nothing wrong with just using the default React export:

import React from 'react';

export default class chainRefeshTool extends React.PureComponent {
    render() {
        return (
            <div>
                <h1>Hello World!</h1>
            </div>
        );
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

The problem here is with you import statement. It should be as follows

import React, { PureComponent } from 'react';

Moreover, when you are extending PureComponent it should be like this:

export default class chainRefeshTool extends PureComponent {

This is because you already imported PureComponent as named export from react. That's why no need to use React.PureComponent while extending.

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.