1

I'm trying to display nested data from a container component unto a view component in react native but anytime the page loads an error message is thrown unto the screen

Container

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import WardsScreens from './WardsScreen';

class WardsContainer extends Component{

  state= {
    wardsData:[
      {
        name: 'Amy Farha',
        avatar_url: 'https://s3.amazonaws.com/uifaces/faces/twitter/ladylexy/128.jpg',
        subtitle: 'Vice President'
      },
      {
        name: 'Chris Jackson',
        avatar_url: 'https://s3.amazonaws.com/uifaces/faces/twitter/adhamdannaway/128.jpg',
        subtitle: 'Vice Chairman'
      },

    ]
  } 
  render() {
    return (
     <WardsScreens
      displayView = {this.state.wardsData}
     />
    );
  }
}

export default WardsContainer;

View Component

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import { List, ListItem } from 'react-native-elements'


const WardsScreens =({displayView})=>(
      <List containerStyle={{marginBottom: 20}}>
      {
        displayView.map((item) => (
          <ListItem
            roundAvatar
            avatar={{uri:item.avatar_url}}
            key={item.name}
            title={item.name}
          />
        ))
      }
    </List>
    )

export default WardsScreens;

But when the page is rendered i get this error

Invariant Violation: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Any help on how to get this done

1 Answer 1

1

This error is if component is not export from the file you are importing from. The error might be that you are importing from wrong file(assuming filename be same as your component name)

import WardsScreens from './WardsScreen';

should be

import WardsScreens from './WardsScreens';
Sign up to request clarification or add additional context in comments.

Comments

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.