Im building a user profile which renders 4 lists:
- reviews
- saved posts.
- created posts
- active posts.
2-4 are lists rendering the same component and 1 is a a list that renders a different component - ReviewCard.
As far as I know, there's some way to make a generic component to render a list of components by type or something of the sort. Each list also has it's own states and additional sub-components like for example star container in reviews which doesnt exists in the others. Right now my code is extremely messy:
useEffect(() => {
if (type === 'reviews') {
fetchReviews()
}
dispatch(fetchNewRoom())
}, [])
useEffect(() => {
setInitialMessages(messages?.slice(0, 3))
}, [messages])
useEffect(() => {
setInitialRooms(rooms?.slice(0, 3))
}, [rooms])
where rooms, reviews and messages are 3 lists that i want to render on profile. im sure there's a better practice for that. Would be great to discuss ideas. Thanks for helping out
In your use-case, there are four list which could be rendered inside a container, where container will have list and common config. In case if there is config which is not constant then pass props and handle it accordingly. Below is the code snippet.
//Below is the list container
//This is the profile component where we you can render 4 list simultaneously.