I building a simple like, bookmark functionality in my react app.
const [liked, setLiked] = useState();
const [bookmarked, setBookmarked] = useState();
useEffect(() => {
post.liked ? setLiked(true): setLiked(false);
post.bookmarked ? setBookmarked(true) : setBookmarked(false);
}, []);
useEffect(() => {
axios.post(`${baseURL}/content/like`).then((res) => console.log(res));
}, [liked]);
Whenever the component gets loaded it useEffect runs twice
How can I avoid intial axios post and axios post only if the state changes?
I want to send a post request whenever the liked State changes.