Hi everyone.
I have:
import React,{useState, useEffect} from 'react'
/* Styles */
import css from './MyComponent.module.sass'
const MyComponent= ({children, className, ...props}) => {
const onOver = (e) => {
console.log(e.target.offsetLeft);
}
//And here i need to add onOver function to each "children" element as onMouseOver event
return(
<ul className={`${css.MyComponentWrap} ${className}`}>
<div className={css.MyComponent}></div>
{children}
</ul>
);
}
export default MyComponent;
How can I do it?
I searched the Internet for an answer, but did not find anything suitable. Is it possible to make all the code in this component so that nothing needs to be added to the component in which it will be used?
P.S. sorry for my bad english))
upd.
const AnotherComponent = () =>{
//here is a huge map function
let mapResult;
return (
<MyComponent>
{mapResult}
</MyComponent>
);
}
I have a huge and hard maping thats why I cannot use @Kox `s answer.
and i need some thing like loop in "MyComponent" and add event or pass it as props.
Actually I can but i thing it not a best solution