An Interest In:
Web News this Week
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
October 18, 2021 07:37 pm GMT
Original Link: https://dev.to/salehmubashar/create-a-unique-id-in-react-js-3f75
Create a unique ID in React JS
Hi Guys
Ok so in this post I will be giving you guys
the simple steps to create a unique reference
ID in react JS.
This has many uses such as giving a user uploaded
image a unique name for saving in a database.
Step 1:
Install UUID v4 using the following command
npm install uuidv4
Step 2:
Import the package into your component, page or code etc.
import { v4 as uuid } from 'uuid';
Step 3:
You can now assign the Uinique ID to any variable using the below code
Nameref is an example here, it can be any variable name.
const nameRef = useRef();
And voila!, you're done.
Thanks you all for reading this post.
If it was helpful, please consider following :)
Until next time
Bye!
Original Link: https://dev.to/salehmubashar/create-a-unique-id-in-react-js-3f75
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To