4

I am building a ReactNative + Redux app and am using the ListView component.

In _renderRow() of the ListView, I'd like to return my own cell component (called JobDetailCell that only receives the data in its props from the component that is managing the ListView (called JobsRootComponent).

I came up with the following code so far:

JobsRootComponent.js

import React, {
  Component,
  StyleSheet,
  Text,
  View,
  ListView,
  ActivityIndicatorIOS,
  NavigatorIOS,
  TouchableHighlight
} from 'react-native'

import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { fetchJobs } from '../actions/Actions'
import { JobDetailCell } from './JobDetailCell'
import { JobDetailComponent } from './JobDetailComponent'

class JobsRootComponent extends Component {

  ...

  _renderRow(rowData) {
      const title = rowData.title
      const subtitle = rowData.by
      return (
        <JobDetailCell title={title} subtitle={subtitle}></JobDetailCell>
      )
  }

  ...

  render() {
    return (
        <ListView
          style={styles.container}
          dataSource={this.props.dataSource}
          renderRow={this._renderRow}
        />
      )
  }

  ...

}

JobDetailCell.js

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

export default class JobDetailCell extends Component {

  render() {
    return (
      <View style={styles.cellContainer}>
        <Text style={styles.cellTitle}>{this.props.title}</Text>
        <Text style={styles.cellSubtitle}>{this.props.subtitle}</Text>
      </View>
    )
  }

}

However, when I am running the app, I get the following errors in the chrome dev console:

ExceptionsManager.js:76 Warning:

React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of StaticRenderer.

Can someone tell me what I am doing wrong here?

2
  • Please add the import/require section of the files, these kind of problems rely in that part a lot of the time. Commented Mar 30, 2016 at 10:07
  • sure, I updated the post and added the imports. Commented Mar 30, 2016 at 10:10

1 Answer 1

5

The problem is that you are importing your components in the wrong way.

This line

import { JobDetailCell } from './JobDetailCell'

Is equivalent to this line:

var JobDetailCell = require('./JobDetailCell').JobDetailCell;

Which gets undefined since you exported the component itself, which has no field named JobDetailCell.

This is how you should import your component:

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

1 Comment

Wasted hours behind it and then finally. Thank you.

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.