Home > Net >  Save HTML in Firebase using React
Save HTML in Firebase using React

Time:07-05

Is there anyway to save the current HTML in firebase? I implemented a function where I can create a div on click but after reseting the app, the created div disapear. Thanks.

CodePudding user response:

Yes, it is possible. you can use draft.js for it. in short you need to store data as JSON using

JSON.strigify()

which convert JSON to string so that firebase can store it as it is. when you retrieve data use

JSON.parse()

which will convert string to JSON again.

CodePudding user response:

Hello thanks for your help. Yes I can post my code:

 // Creating New Div

const [data, setData] = useState("");
const [print,setPrint] = useState(false);

function getData (val){
    setData(val.target.value)
    console.log(val.target.value)
}



const createNewDiv = () => {
    ReactDom.render(
        <div className="content-box home">
            {
                print?
                <p>{data}</p>
                :'Fail'
            }
          
        </div>, document.getElementById('new-element')
    )
}



const createNewInput = () => {
    ReactDom.render(
        <div>
            <div>
                {print?<h1>{data}</h1>:false}
            </div>
            <input
            type="text"
            onChange={getData}
            id="message"
            placeholder="Input Your Content:"/>
            <button className="btn-send-new-div" onClick={() => {
                setPrint(true)
                createNewDiv()
            }}>Send</button>
        </div>, document.getElementById('new-element')
    )

}
  • Related