0

here is my data.js file from which I am getting data

const data2 =
[
    {
        key:1,
        about: "AC services",
        description: "description about service",

    },

   {
        key:2,
        about: "Baby sitter",
        description: "description about service"

    },

    {
        key:3,
        about: "Electronics",
        description: "description about service"

    },
.
.
.  
    ]

export default data2;

here is my code where I am using map function to fetch data

import React from 'react';
import { Container, Header, Content, List, ListItem, Text, Left, Body, Right, Button, Thumbnail, Title } from 'native-base';
import data from '../Constant/data'
const ServiceList = (props) => {
  return (
    <Container>
      <Header>
        <Body>
          <Title> Services List </Title>
        </Body>
      </Header>
      <Content>

        <List>
        {data.map(obj =>
          <ListItem thumbnail>
            <Left>
        <Text>{obj.key}</Text>
              <Thumbnail square source={require('../Assets/serviceIcons/ac.png')} /> **want to get all image also**
            </Left>
            <Body>
              <Text>{obj.about}</Text>
            </Body>
            <Right>
              <Button transparent onPress={() => props.navigation.navigate('BookPage',{obj:obj})}>
                <Text>View</Text>
              </Button>
            </Right>
          </ListItem>
          )}
        </List>

      </Content>
    </Container>
  );
}

export default ServiceList;

result enter image description here

my problem is, I want to fetch the image URL from the data file so that every icon can be rendered also, but I don't know how to code URL in the data file and fetch that into component

2 Answers 2

1

Add one more property "imageUrl" for each object

cont data = [
  ...
  {
    key:3,
    about: "Electronics",
    description: "description about service",
    imageUrl: require("../Assets/serviceIcons/ac.png")
  }
]

and use it like below

{data.map(obj => (
  ...
  <Image source={obj.imageUrl}/>
))}
Sign up to request clarification or add additional context in comments.

1 Comment

I have tried it but coded it incorrectly, thanks, it worked now
0

Put your data in your data file

{
  key:3,
  about: "Electronics",
  description: "description about service"
  image: <your-path-here>
},

1 Comment

I have tried it but coded it incorrectly, thanks, it worked now

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.