Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
React native onPress = change source code of image

i have an array of objects in another file, i map that in 2 file how to do : e.target.src in react-native beacuse in react-native we dont have e

// store file:

export default [
        {
            liked: false,
        },
        { 
            liked: false,
        },
        {
            liked: false,
        },
        {
            liked: false,
        },
        
]

// 2 file

import images from 'store.js'

function unlike (){
// in react will be """ e.target.src = '../assets/unliked.png'  """  but how in react-native ?
}
function like (){
    // in react will be """ e.target.src = '../assets/liked.png' """ but how in react-native ?
}
return(
    <ScrollView>
                {images.map(image => {
                    return({image.liked ? <Image onPress={unlike} source={require('../assets/liked.png')} /> : <Image onPress={unlike} source={require('../assets/unliked.png')} />
              </ScrollView >
)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can import both images beforehand and dynamically set image source based on liked or not. To re-render the UI on each like or dislike use a state :

import images from 'store.js'
import React, { useState, useEffect } from 'react';
// other imports

const liked = require('../assets/liked.png')
const disliked = require('../assets/unliked.png')


const LikesComponent = (props) => {
  const [likesState, setLikesState] = useState(images)

  const handleLikes = (index) => {
    let temp = [...likesState]
    temp[index].liked = !temp[index].liked

    setLikesState(temp)
  }

  return(
    <ScrollView>
       {
       likesState.map((image, index) => <Image key={index} 
                                               source={image.liked ? liked : disliked} 
                                               onPress={() => handleLikes(index)} />
       }
    </ScrollView>
  )
}

export default LikesComponent
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!