URL Shortening API Landing Page with React JS and Tailwind CSS
Design comparison
Solution retrospective
Hello, I had a difficulty with using react dynamic Refs.
I want to use it for the copy url button (ResultList.js file), and for now I'm using normal js function 'document.getElementById( )' in the copyLink function
Please leave a comment if you know how to implement react dynamic Refs !
Community feedback
- @EileenpkPosted almost 2 years ago
Hi Revin! your project looks great, and I made a merge request on your GitHub repo to show you how I added a ref to your project as you asked. I just commented out the old code so after you merge you can go back and clean it up.
It's important to note that using dynamic refs to access DOM elements and React components should be used with care, as it can make the code more difficult to understand and maintain.
Also, with the release of React 16.3, you can use the callback method of creating refs, this method is recommended, and how I implemented the solution. Basically what I did was-
const ref = useCallback(node => { if (node !== null) { // do something with the node navigator.clipboard.writeText(node.innerText); } }, []); <p ref={ref} id={`result-${result.id}`}></p>
Hope you found this helpful!
- Let's connect on LinkedIn! - @Eileenpk
Marked as helpful1@revin212Posted almost 2 years ago@Eileenpk Thats the first time I got a merge request by someone!
How should I respond to the merge request?
Anyway, thankyou so much for the feedback, I'll read more about useCallback!
0@EileenpkPosted almost 2 years ago@revin212, I'm so happy I could help!
To accept a merge request, above the changed code, click Review changes. Type a comment summarizing your feedback on the proposed changes. Select Approve to approve merging the changes proposed in the pull request. Click Submit review. Here is a link to the GitHub docs if you need more help.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/merging-a-pull-request
Let me know if you like the commit message format I used and if you found it to be clear, I have started to use a standard format for my commits that I got from reading an article. (I reposted it on my LinkedIn feed if you want to read it) I'm wondering if it's helpful to other people reading my code on GitHub.
Hope you found this helpful!
- Let's connect on LinkedIn! - @Eileenpk
Marked as helpful1@revin212Posted almost 2 years ago@Eileenpk Thankyou for the response, the commit message is clear and to the point !
0
Please log in to post a comment
Log in with GitHubJoin 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