(React) PNG Image will import, but won't display - reactjs

I'm trying to create a helper function that will return one of two images-- either a check mark or a red error icon, depending on user input.
My header code looks like this
import ErrorImage from './../Assets/Error.png'
import CheckMark from './../Assets/CheckMark.png'
My helper function looks like this:
if(myVar){
return <img src={CheckMark} alt='CheckMark'/>
}
else{
return <img src={ErrorImage} alt='Error'/>
}
I'm positive that I'm importing both correctly-- they're in the same relative file path, and came from the same page source. The weird thing is, only the red x will load. The check mark is showing up as a blank image when I try to follow the path in inspect element. However, when I open the check mark in my assets folder, I get the check mark that I'd expect to see.
For reference, I'm using this image for the check mark and this image for the error icon.
I've tried setting the height and width to arbitrarily large numbers, just to make sure that I'm not creating an image with 0 size, and I've set the opacity to 1, in case it was transparent for some reason. Neither of these made the image appear.
All I can think of is that it must be a property of the image that is causing this issue, but I've tried four or five different check mark images, and none of them have worked. I don't understand what I'm doing incorrectly, and all of the supporting documentation I've found has been for improperly importing the data. So far as I can tell, I'm importing this data correctly.
Edit: One weird element that I've noticed. If I console.log my error icon, I get a long string of text beginning with "data: image/png.base64...." If I console.log my checkmark, I get "static/media/Checkmark.89156a.png" and that's it. I have much, MUCH more data for the error icon than the checkmark.
Edit 2: I still don't know what caused this issue, but I just abandoned trying to import images and swapped over to using Unicode symbols, and that's working for me without issue.

Seems like you have some syntax errors in your code
The header should be:
import ErrorImage from './../Assets/Error.png'
import CheckMark from './../Assets/CheckMark.png'
The helper function should be:
if(myVar){
return <img src={CheckMark} alt='CheckMark'/>
}
else{
return <img src={ErrorImage} alt='Error'/>
}
See this StackOverflow post for more details

The issue here was one of permissions, I believe. As I eventually learned, if I said
const checkMark = require('./../Assets/checkMark.png')
I could load the checkMark. It's a function of webPack. This post explains it well enough.

Related

react-swipeable-list is not working as expected

I'm using #sandstreamdev/react-swipeable-list package in one of my project to create a swipeable list with React. Explored the docs and thought of experimenting with one of the examples mentioned in it. Here is the application created by copying code from the given example. But it is behaving unexpectedly.
Actual Behavior:
Expected Behavior:
Whenever the list item shown is swiped right or left it should display reply or delete option accordingly under the list item. But instead the options are shown all the time. I think the issue here is with the CSS but I'm not sure exactly where I messed it up. Please help me in resolving this issue.
You forgot to import the css of the library.
import '#sandstreamdev/react-swipeable-list/dist/styles.css';
here is the fix
https://codesandbox.io/s/twilight-waterfall-lhkfo

When making a shield.io badge, is there a way to find the right way to reference a logo name?

I just started trying to use shield.io badges today. I'm a little confused.
When I needed to use the C++ logo in a label I used the following request:
https://img.shields.io/badge/C++-%2300599C.svg?&style=for-the-badge&logo=c%2B%2B&logoColor=white
Which yielded a label with a logo, as intended.
I expected it to be logo=c-plus-plus and through trial and error I eventually found out that I should use the encoding for the + sign, %2B.
Now I can't find the logo for Selenium, although it is clearly on the simple-vector list (https://simpleicons.org/icons/selenium.svg) and there's nothing odd about this name, no spaces or signs, so I don't know how to find it. logo=selenium should work but it doesn't.
This is what I'm trying:
https://img.shields.io/badge/selenium-%2343B02A.svg?&style=for-the-badge&logo=selenium&logoColor=white
And what I get is a label without logo.
Any thoughts?
PS: I don't have enough reputation to post images so I can't include the resulting images in the text but you can copy the link to see what I mean.
You should follow the url structure fully https://img.shields.io/badge/<LABEL>-<MESSAGE>-<COLOR>. The color property seems wrong.
For Selenium logo request could be like this (without message)
https://img.shields.io/badge/selenium-43B02A.svg?&style=for-the-badge&logo=selenium&logoColor=white.
The parameter for the C++ logo should be cplusplus and the color should be 00599C like https://img.shields.io/badge/C++-00599C.svg?&style=for-the-badge&logo=cplusplus&logoColor=white
https://shields.io/
https://simpleicons.org/
The link that you pasted gives the link now correctly with image
Github link which has most of the shields that you people would require

Creating a responsive barchart in amchart v4

So I read on the docs that responsiveness for amchart 4 is still currently under development, and so perhaps that explains my difficulties here.
I'm trying to create a barchart that will shrink properly without distorting how the data is displayed. I've tried shrinking the parent container with an #media rule, but that distorted the data.
What's happening: When I shrink the view (i.e. open up inspector or run the web app on a smaller machine) half the category labels on the X-axis are disappearing for some strange reason. It seems to be every other label exactly is gone.
I've tried setting:
categoryAxis.minWidth = 0;
As an approximation of v3's minHorizontalGap property but of course they aren't the same.
I've tried setting the column width in hoped that that would influence the labels.
series.columns.template.width = am4core.percent(50);
And finally I've tried setting both the whole chart to responsive, and the categoryAxis:
categoryAxis.responsive.enabled = true;
But doing this gives me the following error which I can't find support for online:
bootstrap:114 Uncaught (in promise) Error: Loading chunk vendors~responsivedefaults failed.
I'm not sure what the problem is or how to resolve it, I can't believe they'd release a version of amcharts that didn't have responsivity in this age, and so I think it has to be something I'm doing wrong.
So I found the v4 equivalent to minHorizontalGap and that has solved the problem for me.
categoryAxis.renderer.minGridDistance = 60;
It's as simple as that. I still don't know why responsive.enabled doesn't work, but this is a satisfactory solution.

React-Native: Code compiling correctly but screens are empty

I am fairly new to react native and have been attempting to build a very simple registration app.
Currently I have 2 screens running, the first landingscreen.js includes a button to prompt the first registration screen.
This screen works fine but its title shows as blank. (I am using react-navigator)
Below is the screen and you can find the corresponding code here.
On clicking the register here button the next screen is prompted which should show two fields an email and password field with the title "Let's create an account". As you can see below , all that works is the next button but I have no compilation errors. The code pertaining to this screen may be accessed here.
Any help or way pointing would be more than appreciated.
Thanks,
J.
Change navigation(you have written navigtion) spelling
static navigationOptions= {
title: "Let's make an account",
}
The headers not being seen was solved as #Paras Watts noted by fixing a spelling mistake.
To get the fields to show I then put the jsx pertaining to the form in the same render as the navigation also changing any tags to view to stick to the format of jsx.

URLImages in list renderer disappearing on iOS

I have a custom list renderer that has a logo for a business in it. It has a label Logo_URLImage that has the placeholder image. In my code I get the data and assign HashMaps to the list model, h.put("Logo_URLImage",imageURL); where imageURL is a string that has the absolute URL to the image.
On Android it seems to always work, but most of the testing has been on iOS devices. What happens is that images are updated as you'd expect the first time or two that you run it. A run later on will show blank images (flash the place holder image and then blank) and once that happens images will never come back.
Any thoughts on what might be causing this?
Check that you defined the LogoName map entry. Check that it is unique per image?
Check that it doesn't include special characters that might cause an issue.

Resources