Good morning, stackoverflow!
In light of learning ReactJS in my free time between school and work, I've been trying to figure out an effective way to refresh SQL data retrieved once a new result has been submitted. I created a custom review system for my mechanic themed website, once the user submits a new review, it sends it to the SQL system. However, I'm trying to find an effective way to refresh the results on the page once the submit button is hit. I tried running several dependencies in the useEffect hook, I can't find an effective way.
I'm running MySQL, Express, Axios, CORS, and BodyParser
const [reviewList, setReviewList] = useState([])
const [submitDiv, setSubmitDiv] = useState(false)
const toggleSubmit = () => {
setSubmitDiv(!submitDiv)
}
const submitReview = (e) => {
e.preventDefault()
e.target.reset()
Axios.post("http://localhost:3001/submit", {
username: username,
email: email,
reviewtext: reviewtext
})
toggleSubmit()
}
useEffect(() => {
Axios.get('http://localhost:3001/getReviews').then((response) => {
setReviewList(response.data)
console.log("Review list grabbed.")
})
}, [])
Any help would be greatly appreciated!
Any documentation would be appreciated as well.