i have defined an image in spinner.js like so:
import React from 'react';
import broomAndText from './mygif.gif';
function myGif() {
return <img src={broomAndText} alt="broomAndText" width="200px" height="200px" />
}
export default myGif;
i then want to call the image, and display it on page in my mainPage.js. Here's how I am trying to call it:
import myGif from './spinner'
var regData = ""
firestore.collection("profiledata").doc(user.uid).get().then((doc) => {
var firstName = doc.data().firstname;
var lastName = doc.data().lastname;
var companyName = doc.data().companyname;
var email = doc.data().email;
console.log(doc.data().registeringFlag);
regData = doc.data().registeringFlag;
console.log("reg data " + regData)
if (regData == "yes"){
regData = {myGif}
}
}).then(() => {
if (regData != "no") {
document.write(regData)
}
})
what am I doing wrong? It is just outputting [object Object]
document.writeis a proper way to do it. You probably need to useReactDOM.render()and pass yourmyGifinto it as a parameter.console.log(myGif())inmainPage, it still outputs[object Object]. This seems strange to me.ReactDOM.render(myGif, document.getElementById("root")).<img ... />- is much more than just a string. Basically, You can't just convert it into a plain text and put it into a document. Please check my answer below for details.