1

I'm quite new to React and a little stuck. Could someone please explain me how to achieve the following?

I have a child class, something like

import React from 'react';
import PropTypes from 'prop-types';

class testClass extends React.Component {
    render() {
    const {fields} = this.props;

    return (
        <Text>
        blafasel
        </Text>
        )
    }
}

and a parent class like this:

import React from 'react';
import PropTypes from 'prop-types';
import testClass from './TestClass';

class testParentClass extends React.Component {
render() {
    const {fields} = this.props;

    return (
        ---> display testClass here
    );
}

hope you get the idea. Is this possible? I think so. But how?

1 Answer 1

5

You do it the same way you did with Text:

return (
    <testClass />
);

But: Note that React component class names must be initially-capped (and in any case, it's the overwhelming convention in JavaScript to capitalize class names / constructor function names). So TestClass and TestParentClass rather than testClass and testParentClass, and then in TestParentClass's render:

return (
    <TestClass />
);
Sign up to request clarification or add additional context in comments.

1 Comment

Hi T. J., thanks, that did the trick. Didn't expect it to be that easy :)

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.