question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Display a image through require.

See original GitHub issue

Hi all, I don’t understand why this doesn’t work

<FastImage
        source={{
          uri: require('../myfolder/myimage.jpg'),
          priority: FastImage.priority.high,
        }}
        fallback
        style={{
 width: 40, height: 40, borderRadius: 30, padding: 10,
}}
        resizeMode={FastImage.resizeMode.cover}
      />

If I use fallback true, and a default Image component is used, why I still must use a file url? The error I get, of course, is this:

undefined is not a function evaluating source.uri.startsWith('file://')

I know how I can get around the problem (I’d just create a component that shows the default Image component or the fast image one based on certain condition), but I’d like to know if there is a proper way of doing this without the need of adding boilerplate code!

If it’s normal that it doesn’t work, it shouldn’t be harder at all to implement it since you’re already falling back to the Image default component that accepts a required local image

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
Mikunjcommented, Jul 13, 2018
<FastImage
    source={require('../myfolder/myimage.jpg')}
/>

Have you tried doing that? I think it works similar to the source of the Image component.

0reactions
TARASANTANcommented, Jun 19, 2021

Use single dot like <FastImage style={{ width: 720, height: 12000 }} source={require(‘./assets/img.png’)} />

Read more comments on GitHub >

github_iconTop Results From Across the Web

Different Ways to Display Images in React Apps
Different Ways to Display Images in React Apps · Using the import Keyword · Using the require Keyword · Adding SVGs · Adding...
Read more >
Display images in React using JSX without import
You can directly put the source of image if it's placed in public folder without importing or using require, like this.
Read more >
Display an image from a URL / local path in React | bobbyhadz
To display an image from a URL, use the img tag and set its src prop to the complete URL of the image....
Read more >
How to display images from local assets/images folder when ...
Note: As the background image is loaded from CSS file, it's displayed correctly. Only when we load the local image using img tag,...
Read more >
Displaying images with the React Native Image component
You can use either a local or remote file here, and basically, just pass the URI of the image to load it. If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found