M
M
mletov2018-04-18 17:14:36
React
mletov, 2018-04-18 17:14:36

How are react components anyway?

Please tell me. I understand with React, so far there are more questions than answers.
So I decided to fasten the grid and took the most basic example
adazzle.github.io/react-data-grid/scripts/example0...
Questions:
1) In the constructor, this._columns and this.state are accessed, although there are such properties in the class not announced.
How the class should know about them, of course, I have them underlined in red.
2) "TS7006: Parameter 'props' implicitly has an 'any' type." swears at the input parameters of the constructor.
The component code that I got

import * as React from 'react';
import { RouteComponentProps } from 'react-router';
import * as ReactDOM from 'react-dom';
import * as  ReactDOMServer from 'react-dom/server'
import * as ReactDataGrid from 'react-data-grid';



class MyGrid extends React.Component<RouteComponentProps<{}>, {}> {
    constructor(props, context) {
        super(props, context);
        this.createRows();
        this._columns = [
            { key: 'id', name: 'ID' },
            { key: 'title', name: 'Title' },
            { key: 'count', name: 'Count' }];

        this.state = null;
    }

    createRows = () => {
        let rows = [];
        for (let i = 1; i < 1000; i++) {
            rows.push({
                id: i,
                title: 'Title ' + i,
                count: i * 1000
            });
        }

        this._rows = rows;
    };

    rowGetter = (i) => {
        return this._rows[i];
    };

    render() {
        return (
            <ReactDataGrid
                columns={this._columns}
                rowGetter={this.rowGetter}
                rowsCount={this._rows.length}
                minHeight={500} />);
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question