Displaying numerous images in React-Native

I have been working on displaying multiple images from the Marvel API.

For instance, here is a sample:

 "images": [
          {
            "path": "http://i.annihil.us/u/prod/marvel/i/mg/e/00/52264475c3499",
            "extension": "jpg"
          },
          {
            "path": "http://i.annihil.us/u/prod/marvel/i/mg/e/70/51fc0cb22a1ff",
            "extension": "jpg"
          },
          {
            "path": "http://i.annihil.us/u/prod/marvel/i/mg/f/70/51fc0c8f4dee4",
            "extension": "jpg"
          },
          {
            "path": "http://i.annihil.us/u/prod/marvel/i/mg/7/40/51f9695a3ee93",
            "extension": "jpg"
          } ...

And below are some snippets of the code:

class Character extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    let comic  = this.props.character;
    return (
      <View style={styles.container}>
        <Text>{comic.description}</Text>
        <Text style={styles.castTitle}>Characters in this comic:</Text>
        <View>
          {comic.characters.items.map(items =>
            <Text key={items.name} style={styles.castActor}>
              &bull; {items.name}
            </Text>
          )}
        </View>
        <View>
        <View>
          {comic.images.map(images =>
          <ListView  key={images.path}>
            <Image source={{uri: images.path }} style={styles.Images} />
          </ListView>
          )}

        </View>

        </View>
      </View>
    );
  }

I have experimented with various solutions, but when I enclose it in ListView, I encounter this error:

Undefined is not an object (evaluating 'dataSource.rowIdentities')

I am uncertain about the reason behind this issue. Is there a specific approach to rendering multiple images that I should know about?

Best regards, Anker

Answer №1

Hey cousin! ;)

Your issue might be related to how you are utilizing the ListView component in your code. Check out the official documentation on react-native's website for more insights: http://facebook.github.io/react-native/docs/listview.html#listview

You may need to implement something similar to this:

constructor(props) {
  const dataSource = new ListView.DataSource({ rowHasChanged: (row1, row2) => row1.id !== row2.id })
  this.state = {
    dataSource: dataSource.cloneWithRows(props.data)
  }
}
... // Inside the render function
<View>
  <ListView
    dataSource={this.state.dataSource}
    renderRow={rowData => <ListItem data={rowData} />}
  />
</View>
...

This approach may seem unconventional if you're transitioning from web development, but it's crucial for achieving a smooth scrolling experience.

Take care! Sara

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on utilizing AngularJS $http for transferring multipart/form-data

In the process of creating a visual interface that interfaces with various REST services (coded in Java), I am encountering an issue when attempting to call one such service: @PUT @Path("serviceName") public Response serviceName(final FormDataMultiPart mu ...

Exception thrown by ASP.Net Javascript code persists despite being commented out!

In my ASP website, I have incorporated Javascript code in the HEAD section to create a custom context menu. Here is the logic that I initially used: function fileGridGrouping_ContextMenu(s, e) { if(e.objectType != "row") return; fileGridGrou ...

Nested modal in native app utilizes the React Carbon TextInput component for an uneditable input field

As a newcomer to React, I have encountered an issue with the Tauri framework used to bundle my React application as a desktop app. Specifically, I am facing a problem where the TextInput field, nested inside a modal and utilizing React Carbon components, i ...

Selenium: The server has shut down with status code 127

I've tried many solutions from other posts, but none of them have been effective in resolving the error I'm encountering. Currently, I am using bash on Windows and my goal is to simply execute npm selenium-webdriver code. However, even that seem ...

Matlab's capability for dynamic string formatting

Currently, I am working on a Matlab program that requires taking user input for the number of rows to be displayed and then printing a pattern like the following: 1 2 2 3 3 3 and so on... While I have achieved this output using two for loops, I am curio ...

Using JavaScript on an iPhone to automatically launch Safari when clicking on a link from a non-default iOS

When "googlechrome://www.lego.com" is opened in mobile Safari, it switches to the Google Chrome iOS app to open the URL. This feature allows for scriptlets like the following one, which enables you to open the current page in the Google Chrome iOS app from ...

Assign properties to a component from an object

I'm working on connecting React Components to Objects by passing imported Components as Props. const [showComponent, setShowComponent] = useState([ { cId: 1, componentName: <ContactDialogAddresses />, title: 'Address', render: true ...

Connecting actions and reducers through promises in React

My current approach involves making two http requests to an API in order to retrieve data. getServerDetails(this.props.match.params.id) //1 .then(res => { this.props.getServerDetailsAction({ success: true, data: res.data }) ...

Guide on calculating the total of array elements raised to the power of 3

For my project, I want to implement a feature where the user inputs a number (e.g. 5) and the program displays the result of the following mathematical operation: 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 + 5*5*5. Here is the snippet of code I have written: public st ...

Generating a dynamic list of reactive checkboxes in vue.js using data from API call

I'm currently working on a vue.js component that utilizes a search field to query the Google Places API (for simplicity, I've removed some details). The response from the API is a list of checkboxes representing different places. My goal is to se ...

Initiate the execution of JavaScript functions in the loaded partial view using Ajax

I am currently working with a javaScript function that loads a partial view within my page's layout using the following logic: $('.follow-tasks').click(function (e) { e.preventDefault(); var $followtaskList = $("#td-" + $(this).attr ...

Prevent anchor link click and drag functionality on an HTML page / Swipe through a container containing links

Is there a way to prevent clicking and dragging on a link in a webpage? When you click the left mouse button on a link and drag it, you can unintentionally move the link or open a new tab. I am looking for a way to disable this behavior using JavaScript o ...

How to retrieve response cookies using RxJS Ajax

When using RxJS to make an Ajax call request, I am able to set the headers of the request. However, I am wondering how I can retrieve the Cookie from the RxJS Ajax Response? import { ajax } from 'rxjs/ajax'; ajax({ url: "some url", body: ...

Utilize a JSON file to generate a network visualization using the vis.js library

I am currently working with vis.js to generate a visualization. In the example code, I am using the file saveAndLoad.html. The save function works well as it allows me to export a json file. However, I am encountering an issue when trying to load the jso ...

Replacements of JSON null values within Mantle

Utilizing Mantle for parsing JSON data, the typical structure includes: "fields": { "foobar": 41 } However, there are instances where the value of foobar is null: "fields": { "foobar": null } This leads to an exception being thrown ...

VeeValidate fails to validate input fields in a form that is constantly changing

My goal is to create dynamic forms with validations using veeValidate in Vue.js. I am attempting to achieve this by storing an array of objects within the component's data. For instance: data(){ return{ inputs: [ { id: 1, lab ...

Having trouble parsing JSON data? Wondering how to troubleshoot this issue?

I need help with an API call that is causing an error. The code for my getData() function is as follows: func getData(from url: String) { URLSession.shared.dataTask(with: URL(string: url)!, completionHandler: { data, response, error in guard let da ...

The Jquery .remove() function will only take effect after the second click

I am currently working on implementing a notifications feature using bootstrap popover. The issue I am facing is that after a user clicks on a notification, it should be removed. However, for some reason, it requires two clicks to actually remove the notif ...

Creating a signing key for PhoneGap on Windows for iOS applications

Lately, many developers have been inquiring about how to use PhoneGapBuild (PGB) on a Windows machine for iOS app development. The main obstacle they face is not the actual development process, but rather obtaining a key that PGB needs to build the iOS app ...

The application's in-app billing feature is experiencing issues with processing actual transactions

My app's alpha version is up and running. I've opened the alpha for testing. Successfully tested in-app billing using a test account (no money charged). Also, successfully tested the purchase with static response. However, when trying to test r ...