Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic list of posts implemented #1136

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

robsza1122
Copy link

@robsza1122 robsza1122 commented Jul 12, 2024

Copy link

@natalia-klonowska natalia-klonowska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add link to demo in pr description
image

Comment on lines 116 to 137
users,
setUsers,
selectedUser,
setSelectedUser,
error,
setError,
posts,
setPosts,
postsLoading,
setPostsLoading,
errorNotification,
setErrorNotification,
selectedPost,
setSelectedPost,
commentsFromPost,
setCommentsFromPost,
commentLoading,
setCommentLoading,
showCommentField,
setShowCommentField,
loadComments,
onDeleteComment,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider creating handlers for state management functions and moving related logic into those handlers for better organization and readability instead of passing setState functions directly

Comment on lines 20 to 22
useEffect(() => {
getUsers().then(setUsers);
}, [setUsers]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

including setUsers in the dependency array is redundant since it's stable and it's better for useEffect to run only once after initial render which is typically desired behavior for data fetching

@robsza1122
Copy link
Author

robsza1122 commented Jul 14, 2024

I dont see this demo in preversion project in "README.md". Otherwise, I hope I did what you mean. I improved readability by creating a three files with state manegement.

Copy link

@natalia-klonowska natalia-klonowska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall you've made great improvements 🚀 but you're still passing useState setters through context which isn't recommended because they should always remain in component that creates them. consider creating handler functions for them or moving the entire logic that uses them into context

link for your demo you can always find in setting or in actions
image
image

Copy link

@natalia-klonowska natalia-klonowska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you still need to add demo link to pr description
image

Comment on lines 68 to 79
error,
setError,
errorNotification,
setErrorNotification,
posts,
setPosts,
postsLoading,
setPostsLoading,
selectedPost,
setSelectedPost,
showComments,
setShowComments,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is that you're passing useState setters like setError and setPosts through context but they should stay in context because that's where they are created. To fix this you need to move all logic that uses them into context or create handler functions. Same is for all your contexts

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need FormContext because you only use it inside NewCommentForm component

Copy link

@natalia-klonowska natalia-klonowska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only FormContext was unnecessary why did you delete others as well? 😦

Copy link

@natalia-klonowska natalia-klonowska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're going in circles so I think it's good enough but in future tasks try to plan what operations and functions context needs because you should't pass through setters of useState (setShowComments, setCommentsFromPost etc) for the same reason why you shouldn't pass them as props

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants