Display a image through require.
See original GitHub issueHi 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:
- Created 5 years ago
- Comments:10 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Have you tried doing that? I think it works similar to the source of the
Image
component.Use single dot like <FastImage style={{ width: 720, height: 12000 }} source={require(‘./assets/img.png’)} />