How to gentrate Unique Id in ReactJs

0 votes

I am new to ReactJS. I want to use Unique Id in my react program. So I create a custom hook, and that hook returns a unique id. But my situation is that when I use this custom hook in my component, at the same time my component is initialized twice. I don't know how to avoid multiple initial loads.

This is my custom Hook

import { useEffect, useReducer } from 'react';

export const CreateUniqueId = () => {
  const [renderId, forceUpdate] = useReducer((x) => x + 1, 0);

  useEffect(() => {
    forceUpdate();
  }, []);

  return renderId;
};

If you know the answer, tell me what I should do.

Thanks in advance.
 

Jan 27 in Others by Tejashwini
• 3,770 points
56 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
1 answer

how to get last insert id after insert query in codeigniter active record

To answer your doubt, try the following ...READ MORE

answered Feb 23, 2022 in Others by Aditya
• 7,680 points
1,892 views
0 votes
2 answers

How to get the URL of the current tab in Google Chrome?

Its so simple.... If you want to ...READ MORE

answered Aug 12, 2020 in Others by Steve
• 200 points
1,770 views
0 votes
1 answer

What is a name function in JavaScript & how to define it?

A named function declares a name as ...READ MORE

answered Mar 7, 2019 in Others by Frankie
• 9,830 points
2,655 views
0 votes
1 answer
0 votes
1 answer

How to unistall a file in Linux?

You can uninstall a file using the ...READ MORE

answered Mar 8, 2019 in Others by Nabarupa
913 views
0 votes
0 answers

How to handle large http response data from observer in Angular application to avoid browser crash?

Suppose we have a angular application which ...READ MORE

Apr 19, 2019 in Others by Hemant Gajbe
1,971 views
0 votes
1 answer

How can I remove a port from url for node app using nginx

If you run your node server on ...READ MORE

answered Apr 10, 2018 in DevOps on Cloud by ajs3033
• 7,300 points
3,082 views
0 votes
3 answers

ReactJS vs Angular Comparison: Which is better?

One picture, many facts How can you compare ...READ MORE

answered Aug 11, 2018 in Events & Trending Topics by slayer
• 29,350 points
661 views
+2 votes
4 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP