Search code examples
reactjsgoogle-cloud-firestorepage-refresh

button with onClick={refreshPage}


Using React, Firestore V9 I have an addDoc function that add user's input to firestore collection, but user needs to refresh the page to see his input. How can I reprogramm my code to immediately refresh the page after user clicks on submit button? Code:

<input placeholder='firestore' onChange={ (event) => {
          setAnswer(event.target.value);
            
        }}/> 
<button onClick={createUser}>send to firestore</button>

What about adding to button an second onClick={refreshPage}?


Solution

  • You can use .then to make sure it reloads after addDoc is done adding the document to firestore

    addDoc() // your document insert logic
    .then(()=>{
    window.location.reload() //here comes your reload logic
    })
    .catch((err)=>{
    console.log(err)
    })