8000 pure function是什么 · Issue #30 · zhouzhongyuan/qa · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
pure function是什么 #30
Open
Open
@zhouzhongyuan

Description

@zhouzhongyuan

问题来源

文件内容如下

import { View, Text } from 'react-native';
import React, { Component } from 'react';
class TestView extends Component {
    render() {
        return (
            <View>
                <Text>TestView</Text>
            </View>
        );
    }
}
export default TestView;

执行eslint发现错误

Component should be written as a pure function

应该改为

const TestView = function () {
    return (
        <View>
            <Text>TestView</Text>
        </View>
    );
};

错误解析

Enforce stateless React Components to be written as a pure function (prefer-stateless-function)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0