I am currently trying to build an next.js app.
So what I want to do is passing a function to a component and call it with useEffect
I have the following component in order to change the props of the parents element. Therefore I pass the function from the parent like this:
<NumberInput name="height" update={manuelUpdate}></NumberInput>
The manuelUpdate function is a another props function from the actual parent:
const manuelUpdate = (name, value) => {
props.update(name, value);
};
It works fine if I run the props.function with the onclick functions. However as soon as I try to use it in useEffect, it returns that the function is not a function.
Maybe I am just thinking to complicated..
this is the component;
const NumberInput = ({ name, min = undefined, max = undefined, ...props }) => {
const minInput = min !== undefined
? min
: null;
const maxInput = max !== undefined
? max
: null;
const [numb, setNumb] = useState(0);
useEffect(() => {
console.log(props.update)
}, [numb]);
const increaseNumb = () => {
if (numb < maxInput || maxInput == null) {
setNumb(numb + 1)
}
props.update(name, numb)
};
const decreaseNumb = () => {
if (numb < minInput || minInput == null) {
setNumb(numb - 1)
}
};
const changeHandler = ({ e }) => {
let n = parseInt(e.target.value)
if (Number.isNaN(n)) {
setNumb(numb)
} else {
setNumb(n)
}
}
return (
<div className={styles.def_number_input, styles.number_input}>
<button onClick={decreaseNumb} className={styles.minus}></button>
<input className={styles.quantity} name="quantity" value={numb} onChange={(e) => changeHandler({ e })}
type="number" />
<button onClick={increaseNumb} className={styles.plus}></button>
</div>
);
};
sorry in advance if my question is stupid or my code messy, I am still in the process of learning 😀
vardenafil coupons manufacturer – brand name vardenafil online vardenafil tablets
generic stromectol for humans – ivermectin tablet 1mg ivermectin for humans
cost cialis australia – cheap cialis pills online cialis 20 mg generic india
generic accutane canada – accutane over the counter uk accutane cream uk
lyrica tablets 300mg – best online canadian pharmacy canadian pharmacy no scripts
cialis 5mg price – buy generic cialis online usa best prices on cialis
ivermectine – ivermectin 4 mg ivermectin where to buy for humans
clomid tablets – order clomid 50mg clomiphene online
purchase vardenafil online – vardeed.com sexual dysfunction
508573 327685Totally pent topic matter, appreciate it for selective details . 991655
522969 913018Wow truly glad i came across your internet site, i??ll be certain to check out back now i??ve bookmarked it??. 272977
order prednisone without prescription – buy predisone steriods buy generic prednisone online
websites for essay writing – i need a paper written for me write my cover letter for me
sildalis medication – oral sildalis metformin brand
purchase ampicillin sale – buy acillin online cheap plaquenil order
hydroxychloroquine 400mg ca – order plaquenil generic plaquenil 400mg oral
cenforce 50mg oral – order zovirax 800mg without prescription acyclovir drug
811113 144056This article gives the light in which we can observe the reality. This is extremely nice one and gives in-depth info. Thanks for this good write-up. 171435