react-nativeextending-classes

Extending a parent and using parent render method react native


This is a general question as I've not seen anything like this anywhere. So if I have a parent component like the examples below and I was to render the children of the child in the parent how could I do this if its possible (other than making a getParentComponent(children) method in the parent). Is there a was that when the child render gets called that the child content automatically gets inserted?

import React, {Component} from 'react';
import {View} from 'react--native;

class CustomView extends Component {
    render() {
        return (
            <View style={styels.customStyle}>
                // this is where I want to render my child content
            </View>
        )
    }
}

import React, {Component} from 'react';
import {CustomView} from 'somewhere;

class ChildView extends CustomView {
    render() {
        return (
            <View style={styels.childStyle}>
                // take this view and all the content with in and render it in the parent render
            </View>
        )
    }
}

Solution

  • By nature, a parent class has no knowledge of any class that extends it. So, no. MDN extends documentation explains more.

    Otherwise, refs might help you get access to a Component's props, like children.