我试图在react中抽象处理事件,因此,而不是
export const Button = ({handlerFunction, text}) => {
return(
<button onClick = {()=>handlerFunction()} >{text}</button>
)}
类似于
export const Button = ({handlingEvent, handlerFunction, text}) => {
return(
<button `{handlingEvent}` = {()=>handlerFunction()} >{text}</button>
)}
当然不起作用。一些想法?谢谢! !
export const Button = ({
handlingEvent,
handlerFunction,
text
}) => {
return (
<button {...{ [handlingEvent]: () => handlerFunction()}}>
{text}
</button>
)
}