I have a component which renders "react-icons" object. However, if no icon is supplied I want to display "NoIcon" string on the UI.
The component A is as such.
component A
import React from 'react';
import { FaHeart} from "react-icons/fa";
const Icon = ({FaIcon = "NoIcon"}) => {
return (
<div>
<FaIcon/>
</div>
);
};
export default Icon;
and calling this component from another components B works :
component B
import React from 'react';
import Icon from './components/icons/icon';
import { FaHeartBroken } from "react-icons/fa";
class App extends React.Component {
render(){
return(
<Icon FaIcon={ FaHeartBroken }/>
)
}
}
export default App;
this returns a "Broken Heart Icon" i.e 💔.
But, if no icon is supplied in component B it should return a text i.e "NoIcon" in the UI.
Component B
....
....
<Icon FaIcon/>
....
however this raises an error
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: boolean.
Check the render method of `Icon`.
I also tried to set an or method on component A for value assignment, which did not work either.
Why providing no argument within Icon component, calling for a Boolean check?
component A
const Icon = ({FaIcon = FaHeart || "NoIcon"}) => {
....
Also tried these variations. These do not raise any error but do not return any value on the UI either.
component B
...
<Icon/>
<Icon FaIcon = "Test"/>
<Icon FaIcon = {"Test"}/>
How do we resolve this?