Answer the question
In order to leave comments, you need to log in
How to pass handleIncrement/handleDecrement to another file's function via props?
I have 2 files first
const handleIncrement = (value) => {
let countersIncrement = counters.map((i) => {
return (i.value = value + 1);
});
setCounters(countersIncrement);
};
const handleDencrement = (value) => {
let countersDencrement = counters.map((d) => {
return (d.value = value - 1);
});
setCounters(countersDencrement);
};
return (
<>
{counters.map((count) => {
return (
<Counter
key={count.id}
onDelete={handleDelete}
onIncrement={handleIncrement}
onDecrement={handleDencrement}
{...count}
/>
const handleIncrement = () => {
props.onIncrement(props.value);
// setValue((prevState) => prevState + 1);
};
const handleDencrement = () => {
props.onDencrement(props.value);
// setValue((prevState) => prevState - 1);
};
return (
<div>
<span>{props.name}</span>
<span className={getBageClasses()}>{formatValue()}</span>
<button
className="btn btn-primary btn-sm m-2"
onClick={() => props.onIncrement(props.value)}
>
+
</button>
<button
className="btn btn-primary btn-sm m-2"
onClick={() => props.onDencrement(props.value)}
>
-
</button>
[
{ id: 0, value: 0, name: "Ненужная вещь" },
{ id: 1, value: 4, name: "Ложка" },
{ id: 2, value: 0, name: "Вилка" },
{ id: 3, value: 0, name: "Тарелка" },
{ id: 4, value: 0, name: "Набор минималиста" },
];
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question