|
-
August 3rd, 2025, 03:58 PM
#1
React: useEffect() Dependencies Questions?
I'm watching the video:
React JS Full Course for Beginners | Complete All-in-One Tutorial | 9 Hours
https://www.youtube.com/watch?v=RVFAyFWO4go
(Specifically, Chapter 19: Axios API Requests at 6:29:42)
I tried to get ahold of the video?s author, but no luck?
The example shown in the video uses the following code:
Code:
const EditPost = ({
posts, handleEdit, editBody, setEditBody, editTitle, setEditTitle
}) => {
const { id } = useParams();
const post = posts.find(post => (post.id).toString() === id);
useEffect(() => {
if (post) {
setEditTitle(post.title);
setEditBody(post.body);
}
}, [post, setEditTitle, setEditBody])
return (
<div> nothing here yet... </div>
)
}
Why are post, setEditTitle, and setEditBody included in the useEffect() dependency array? What effect does including them have? Why is useEffect() needed at all here? Can't we just set the values directly?
Thanks, just please be sure to review CH 19 in this video, it will explain everything that I am asking about...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|