Open jose-esquivel opened 4 days ago
Nice work! The server code was well organized and easy to follow! One thing I noticed is that the deployed site doesn't seem to work for. It seems like the fetch
es are hitting localhost:3000
instead of the production backend.
However, I didn't see any mention of localhost in the code, so I assume this was fixed but the fix hasn't been deployed yet?
CardList.jsx
renders not only the list of cards, but also the "Create New Card" button (and the Creation dialog). I think it would make sense (if feasible) to split these up into 2 separate components - a CardList and a "NewCardButton" (or whatever).cards
state such that we only modify the array item that corresponds to the card we just updated. It might look something like this:
setCards(prevCards => prevCards.map(prevCard => prevCard.id === id ? card : prevCard))
(where card
comes from the response to the PUT request)App.jsx
, we're updating React state after the network request completes. The issue with this is that, if a user takes some action that results in multiple fetch
es issued in quick succession (e.g. upvote a card and then quickly switch to another board), the response to the first fetch
might be received after the response to the second fetch
. In this case, we'd clobber the React state that we just set from the second fetch
. In practice, this probably won't happen, but if the app was being used by a lot of users, they might eventually hit a bug caused by this issue. So something to keep in mind, but I definitely don't expect a newcomer to handle this edge-case.img_url
maybe imgUrl
to keep the naming style ("camel case") consistent throughout the app.Great work again, Ogenna!
I'm happy to see how you continue to develop your knowledge and coding style through these projects.
Hey, a bit of a late review, but this project looks good! I have a couple points of feedback:
<Button name="All" />
<Button name="Recent" />
<Button name="Celebration" />
<Button name="Thank You" />
<Button name="Inspiration" />
I'd do something like:
const buttons = {...}
return buttons.map(({name}) => <Button name={name} />)
It's a bit silly now, but when you have multiple of the same props and stylings and more than 5 objects, it saves a lot of time/redundancy.
handleDisplayBoard
and handleDeleteBoard
could have been handled more efficiently. For context, handleDisplayBoard
makes a call to our backend to fetch data. That call could be computationally expensive.We also have a local state const [boards, setBoards] = useState([]);
that tracks the boards currently on display in the screen. When we delete a board via handleDeleteBoard
. We call handleDisplayBoard
and make that fetch all over again -- in cases where network fetching is expensive, so we want to avoid doing so!
Instead I would have like to have seen treating the local state as a "cache". In handleDeleteBoard
, we write to our db. We know what our local state should look like, so we can update this as well directly. We do not call handleDisplayBoard
again. We only should fetch maybe once per refresh. This would look something like:
async function handleDisplayBoard() {
const response = await fetch("http://localhost:3000/boards", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
const data = await response.json();
setBoards(data);
}
useEffect(() => {
handleDisplayBoard();
});
async function handleDeleteBoard(id) {
try {
const response = await fetch(`http://localhost:3000/boards/${id}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
});
if (response.ok) {
setBoards(boards.filter(boards => board.id != id))
}
} catch (err) {
console.log(err);
}
}
Notice how we update our local state without making a roundabout fetch from our db. There's more optimizations to be done with caching, maybe turning the list into an object for O(1) indexing. But the principles remains the same: network calls are performance intensive, optimizing these calls increases app responsivity!
You probabaly already know this, but here's a primer on big-O notation (just in case). It's applicable for front-end too! https://www.shecodes.io/athena/52559-understanding-big-o-notation-in-javascript#:~:text=Big%20O%20notation%20is%20a,the%20more%20time%20it%20takes.
Thread for providing feedback for Ogenna's third week project.
Commits: https://github.com/Iamogeee/KUDOS-BOARD/commits/main/