T
T
Theory Theory2020-11-15 16:45:10
React
Theory Theory, 2020-11-15 16:45:10

Error props is not defined?

class Parent extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
            <div>
                {props.title}
            </div>
        );
    }
}



class Children extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
            <Parent title="13"/>
        );
    }
}

ReactDOM.render(
    <Children />,
    document.querySelector('#root')
);


As a result: props is not defined. The above error occurred in the Parent component:

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Askhat Bikmetov, 2020-11-15
@Narbek

Props go to the arguments to the constructor and the render function (still in hooks, but not about that now). In your case, you can define the props argument for the render method, but it's better to just writethis.props

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question