React Native - invalid prop children

Alter

I've created a few components. One of them should allow nesting however it inexplicably does not (inexplicable because I couldn't find any posts with quite this problem)

There is one image required to run this (it can be replaced with anything)

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import { View, StatusBar, StyleSheet, ImageBackground } from 'react-native';

export class PhonyStatusBar extends Component {
  render () {
    return (
        <View style={styles.statusBar} />
    );
  }
}

export class HomeScreen extends Component {
  static propTypes = {
      children: PropTypes.string
  }

  render () {
      return (
        <View>
            {this.props.children}
        </View>
      );
  }
}

export class AppGrid extends Component {
  render () {
    return (
      <View />
    );
  }
}

export default class App extends Component {
  render() {
    return (
      <View>
        {/* hide system status bar */}
        <StatusBar hidden={true} />
        <PhonyStatusBar />

        {/* throw in our own status bar  */}
        <HomeScreen> 
          <View />
        </HomeScreen>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  backgroundImage: {
      width:'100%',
      height:'100%',
  },
  statusBar: {
    width: '100%',
    height: 25.33,
    backgroundColor: 'rgba(255, 157, 0, 0.5)'
  },
});
Dacre Denny

In react children is a built in prop, already defined by the library, for components. This is not a prop that you should be defining manually. See this for more detail: https://reactjs.org/docs/jsx-in-depth.html#children-in-jsx

Try removing:

 static propTypes = {
      children: PropTypes.string
  }

from HomeScreen to resolve the issue.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

React Native error Failed prop type: Invalid prop `children` of type `array` supplied to `Overlay`,

React native does not return children prop

Invalid prop children in Provider

invalid prop source supplied to image React Native

React Native: Props Warning, invalid prop value

Why is React saying “Invalid prop `children`” types is object not function?

children prop in React component

React. Children as prop

React Snapshot testing with jest - Failed prop type: Invalid prop `children` of type `string` supplied

React router error (Failed prop type: Invalid prop `children` supplied to `Switch`, expected a ReactNode.)

React-Native Image Invalid prop 'source' supplied to Image

Failed prop type: Invalid prop 'value' of type 'object' supplied to 'TextInput' React Native

How to pass a prop to {children} in React?

Array of children passed as prop in react

React Apollo Client Query throwing error "Invalid prop `children` of type `array` supplied to `Query`, expected `function`"

Invalid prop 'children' of type 'array' supplied to overlay. Expected a single react element

React error 'Failed propType: Invalid prop `children` supplied to `Provider`, expected a single ReactElement'

React Native (Android): Couldn't find a 'component', 'getComponent' or 'children' prop for the screen 'Home'

Failed prop type: Invalid prop `children` of type `array` supplied to `GlobalState`

Invalid prop of type `string` in react

React Native + Icons: Warning: Failed prop type: Invalid props.style key tintColor supplied to ForwardRef(Text)

invalid prop value of type number supplied to textinput expected string react native

Pass Children prop to React Memo component

Overriding children prop in React with Typescript 3.5+

Reactive Native - Invalid prop '' supplied to Stylesheet

React Native not rendering on prop change

Passing component as a prop in react native

React Native Android Clipping Children

React native custom view, no propType for native prop