简体   繁体   中英

How to create unique components react?

Hello I am trying to generate unique react components but a problem I have is they share their ReactHooks, how can I have each component not share their hooks and be unique?

When you create a hook in a react component, they are not supposed to interact each other

function component1() {
  const [name, setName] = useState("name1");
  return <component2 />
}

function component2() {
  const [name, setName] = useState("name2");
  return <div>{name}</div>
}

The functions will be unique by default. You're probably doing something wrong somewhere in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM