D
D
Danoneko2022-04-13 19:16:07
JavaScript
Danoneko, 2022-04-13 19:16:07

How to solve props error on duplicate component?

Good afternoon!

Faced a problem when transferring props. There is a parent component Parent which receives callback'om function setValue from Child.

import React, { useState } from "react";

const Parent = () => {
const [value, setValue] = useState([]);
console.log(value);
  return (
          <Child setValue={setValue} name={name1} title={title1}  />
          {/* <Child setValue={setValue} name={name2} title={title2}  /> */}
  );
};


The point is that I need the same component, with different props and a different result of the same function.

Interestingly, the output of the function comes only from the last added child, while in the console the function of the first child outputs and is overwritten by the second.

How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Zhivagin, 2022-04-13
@Krasnodar_etc

Or maybe you somehow have a function called in both child at once?
Otherwise, it should work fine, the function is created in the Parent, the Child just calls it via the prop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question