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

118
Views
Passing image URL to functional component in React native

I want my avatar component to show the avatar with the URL passed to the component. So if I pass avatar1 it shows avatar1. I have tried several methods, but nothing seems to work.

My avatar component looks like this currently. I want to get rid of the static URL

export default function Avatar() {

  return (
    <Image source={require("../assets/avatar.png")} style={styles.avatarStyle} />
  );
}
const styles = StyleSheet.create({
  avatarStyle: {
    resizeMode: 'contain',
    height: "60%",
    alignSelf: "flex-start",
    position: "absolute",
    bottom: 0
  }
});

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Probably you trying to pass this avatar1 via props so you need to use the props, passing it to the function

export default function Avatar({avatarUri}) {
    
      return (
        <Image source={{uri: avatarUri}} style={styles.avatarStyle} />
      );
    }
    const styles = StyleSheet.create({
      avatarStyle: {
        resizeMode: 'contain',
        height: "60%",
        alignSelf: "flex-start",
        position: "absolute",
        bottom: 0
      }
    });

https://reactnative.dev/docs/props

about 4 years ago · Juan Pablo Isaza Report

0

Make sure the next things:

  • Image path check correct path
  • You should add the width style param to the image, it is required to render.
  • resizeMode it's a prop of Image, not a style param

Fixed style:

const styles = StyleSheet.create({
  avatarStyle: {
    height: "60%",
    width: 150, // FOR EXAMPLE
    alignSelf: "flex-start",
    position: "absolute",
    bottom: 0
  }
});

The complete code:

export default function Avatar() {

  return (
    <Image source={require("../assets/avatar.png")} style={styles.avatarStyle} resizeMode='contain'/>
  );
}
const styles = StyleSheet.create({
  avatarStyle: {
    height: "60%",
    width: 150, // FOR EXAMPLE
    alignSelf: "flex-start",
    position: "absolute",
    bottom: 0
  }
});
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!