Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Responsive and Interactive comments section clientside state

#react#vite
Larry 170

@lawrence-yoon

Desktop design screenshot for the Interactive comments section coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
3intermediate
View challenge

Design comparison


SolutionDesign

Solution retrospective


What did you find difficult while building the project?

-The most difficult parts of the project were the algorithms for the CRUD methods applied to the client side app data state. It was tough because the given data.json has an array within the app data object, and that array is an array of other objects, with the possibility of having a further nested array of objects.

Which areas of your code are you unsure of?

-The areas of code that I am unsure of have to do with the previously mentioned algorithms.

Do you have any questions about best practices?

-I do. What is the best practice for importing/exporting/abstracting the handler functions (handleUpdate, handleDelete, etc...)? I have it all at my app.jsx and feel like it is too cluttered.

Community feedback

AC 🍀 340

@alleycaaat

Posted

Nice job completing this project! I'm going to preface my comment by saying I'm not an expert on CRUD apps, I fell down a Jamstack rabbit hole last year and have developed a mild obsession, but I am learning new things with each one I complete. Another sidenote, I formatted my comments in the style of facebook, where there's only the parent comment and all the replies below it (at least that's how I think facebook does it, I haven't been on in years). I didn't go the reddit route where replies to replies get nested.

Tl;dr nesting: I ignored the formatting of the .json file and just used the data.

Your comment about the data being an object and nesting becoming an issue is valid. It depends on how you set things up, how data gets altered and saved. I used context and actually hooked my project up to a Fauna database (I know the db is overkill, don't worry hahah) and made a collection of comments. A collection is similar to a table in other databases, if you have server side experience. Each comment or reply was an individual document, which is how any record or item is stored with Fauna, as a document.

The way I formatted the documents, the comments, can be applied to a front-end only project. All comments had a parent_id key, if it was the original comment it had a value of an empty string, if it was a reply it was given the id of the parent comment for the value. Then I just used the parent_id property to sort out comments versus replies. I disregarded the format of the data.json file provided and just pulled the data out. You certainly could stick with their formatting, but I try not to nest too deep to make my life easier.

Regarding best practices for data handling: again I'm not an expert, but what I do is make a separate folder to throw all the data handling code in, and call functions when needed. I'll then use a useEffect hook to get the data from the server or the .json file to set things up in my App.js file. For example, this is the function I used for the buttons to change the score:

const ModScore = (direction) => {
        const update = AdjustScore(comments, id, direction);
        modComment(id, update);
    };

The plus and minus buttons onClick event handler points to ModScore, here's a link to the AdjustScore code. AdjustScore does the heavy lifting, but in its own separate file. If you're doing a state based project, you can do the same thing, just call the functions from App.js and save the return to state.

I can definitely go into more detail if you'd like if you have more questions or I wasn't clear enough. :)

Cheers!

1

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord