My code is like below but I getting checkSome is not defined error, from inside the checkSome function, how can I call checkSome(el)
useImperativeHandle (ref, ()=> ({
checkSome(prop) {
userIds.push(prop.id);
if (prop.children == null) return;
prop.children.forEach((el) => {
checkSome(el);
});
}}));
Advertisement
Answer
You need to use this keyword. Try this:
useImperativeHandle (ref, ()=> ({
checkSome(prop) {
userIds.push(prop.id);
if (prop.children == null) return;
prop.children.forEach((el) => {
this.checkSome(el);
});
}}));
You can read more from here.